1
沒有見過我的模板類List:指針在導出模板類
template<class T>
class List{
protected:
element<T>* head;
//...
};
,我有模板類設置從列表繼承:
template<class T>
class Set: public List<T>{
public:
void insert(const T& t){
if(!has(t))
pushFront(t);
}
bool has(const T& t){
bool is=false;
element<T>* tmp=head;
while(tmp && !is){
if(Comparator::compare(t, tmp->key))
is=true;
tmp=tmp->next;
}
return is;
}
};
我的問題是,當我想使用element<T>* tmp=head;
行,沒有其他任何東西,我得到錯誤'head' was not declared in this scope
,但是當我在此行(element<T>* tmp=List<T>::head;
)之前添加List<T>::
時,一切正常。爲什麼我得到這個錯誤,當頭受保護,我使用公共繼承?
'List'是一個從屬基類,使用'this-> head'而不是 –