我已经在模板基类的头文件中声明了指针first,last 和 counter ,但是当头文件包含在派生类的定义中时,会发生错误,指出first , last 和 counter未在此范围内声明。但是我之前声明的first、last和counter的头文件已经包含在派生类的头文件和实现文件中了。
//template base class
template <class Type>
class linkedListType
{
.
.
.
protected:
int counter; //to store no. of elements in the list
nodeType<Type> *first; //pointer to first node
nodeType<Type> *last; //pointer to last node
}
//derived class header
#include "linkedListType.h"
using namespace std;
template <class Type>
class unorderedList:public linkedListType<Type>
{
public:
bool searchFor(const Type& searchItem) const;
void insertFirst(const Type& newItem);
void insertLast (const Type& newItem);
void deleteNode(const Type& deleteItem);
};
//derived class definition
template <class Type>
bool unorderedList<Type>::searchFor(const Type& searchItem) const
{
nodeType<Type> *current; //pointer to traverse the list
bool found = false;
current = first; //set current to point to first node
.
.
.
}