在對抽象類的繼承中,需要對其變量也進行重寫,如果出現未定義標識符,因爲該繼承中沒有對其成員進行重寫,例如下面的繼承關係
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;
};
編譯就通過了。
這些僅爲個人見解,希望可以幫到其他人吧。