我对C++模板编程还不熟悉,所以我决定先写一个模板列表。但是在 Node<T> *head;
和 Node<T> *tail;
这两行出现了错误。
以下是我的头文件(因为错误只出现在那里):
#ifndef LIST_H
#define LIST_H
using namespace std;
template <class T> class List {
public:
List();
T get(const int n);
void add(const T element);
private:
Node<T> *head;
Node<T> *tail;
int size;
};
template <class T> class Node {
public :
Node();
T get();
void setNext(const Node<T> *next);
Node<T> getNext();
void setValue(const T value);
private:
T value;
Node *next;
};
#endif // LIST_H
哦,我尝试在Node<T>
前添加typename
,但是它给了我一个expected nested-name-specifier before 'Node'
。