在对抽象类的继承中,需要对其变量也进行重写,如果出现未定义标识符,因为该继承中没有对其成员进行重写,例如下面的继承关系
template<typename T>
class Linearlist
{
public:
Linearlist() {};
virtual bool Isempty()const { return length; };
virtual bool Find(int k, T &b)const = 0;
virtual ~Linearlist() {};
private:
int length;
};
![template<typename T>
class LinearListSqu : public Linearlist<T>
{
public:
LinearListSqu(int Maxlistsize = 10);
~LinearListSqu() { if (element) { delete \[\]element; } };
virtual bool Isempty()const { return length == 0; };
virtual bool Find(int k, T &b)const;rotected:
int Maxsize;
T *element;
};
在继承中没有对length进行重写,则会出现此情况
但是重写之后
[template<typename T>
class LinearListSqu : public Linearlist<T>
{
public:
LinearListSqu(int Maxlistsize = 10);
~LinearListSqu() { if (element) { delete \[\]element; } };
virtual bool Isempty()const { return length == 0; };
virtual bool Find(int k, T &b)const;rotected:
int Maxsize;
T *element;
int length;
};
编译就通过了。
这些仅为个人见解,希望可以帮到其他人吧。