要求: 1.index<0抛出异常eNegative。
2.index=0抛出异常eZero。
3.index>1000 抛出异常eTooBig。
4.index<10抛出异常eTooSmall。
5.eSize类是以上类的父类实现有参数构造,并定义virtual void printErr ( )输出错误。
#include<iostream>
using namespace std;
class MyArray
{
private:
int m_len;
int *m_data;
public:
MyArray(int l);
~MyArray();
int &operator [](int index)
{
return m_data[index];
}
int GetLength()
{
return m_len;
}
class eSize
{
protected:
const char *ErrMsg;
public:
eSize(char *msg):ErrMsg(msg)
{
}
virtual void printErr()=0;
};
class eNegative:public eSize
{
public:
eNegative():eSize("Negative Exception")
{
}
void printErr()
{
cout<<ErrMsg<<endl;
}
};
class eZero:public eSize
{
public:
eZero():eSize("Ze