#include <cstdlib>
#include <vector>
#include <iostream>
using namespace std;
class CFirstLevel {
public:
CFirstLevel (const string & _name): name (_name) {}
// ...
protected:
string name;
};
template <typename T>
class CSecondLevel: public CFirstLevel {
public:
CSecondLevel (const string & _name): CFirstLevel (_name) {}
virtual void PushBack (T) = 0;
virtual void Print (int I) {cout << data [I] << endl;}
// ...
protected:
vector<T> data;
};
template <typename A>
class CThirdLevel: public CSecondLevel<A> {
public:
CThirdLevel (const string & _name): CSecondLevel<A> (_name) {}
virtual void PushBack (A _value) {data.push_back (_value);}
};
int main ( void ) {
CThirdLevel<int> * pointer = new CThirdLevel<int> ("third");
pointer -> PushBack (111);
pointer -> Print (0);
return 0;
}
编译器返回错误:
main.cpp:在成员函数'virtual void CThirdLevel::PushBack(T)'中:
main.cpp:32:37:错误:“数据”未在此范围内声明
哪里有问题?是否可以使用这种继承?