#include "stdafx.h"
#include<iostream>using namespace std;
template<class T>
class wrong{
public:
virtual void show(){
cout<<"发生错误"<<endl;
}
};
template<class T>
class small:public wrong<T>{
public :
int a;
small(int d):a(d),wrong(){
}
void show(){
cout<<"类型:"<<typeid(T).name()<<" 太小了,标准10-100,您输入的是:"<<a<<endl;
}
};
template<class T>
class big:public wrong<T>{
public :
int a;
big(int d):a(d),wrong(){
}
void show(){
cout<<"类型:"<<typeid(T).name()<<" 太大了,标准10-100,您输入的是:"<<a<<endl;
}
};
template<class T>
class myArray{
private: int size;
T* p;
public:
myArray(int n){
if(n<10)
{
throw small<T>(n);
}
else if(n>100){
throw big<T>(n);
}
else{
p=new T[n];
size=n;
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
try{
myArray<double> m(300);
}
catch(wrong<double>&e)
{
e.show();
}
return 0;
}