關於C3861,找不到標識符的解決方案(抽象類的虛繼承)

在對抽象類的繼承中,需要對其變量也進行重寫,如果出現未定義標識符,因爲該繼承中沒有對其成員進行重寫,例如下面的繼承關係

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;
};

編譯就通過了。
這些僅爲個人見解,希望可以幫到其他人吧。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章