我是 C++ 模板编程的新手,所以我决定从编写模板列表开始。我在线收到此错误Node<T> *head;
and 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
哦,我尝试添加typename
before Node<T>
,但它给了我expected nested-name-specifier before 'Node'
.
把你的Node
前面的定义List
或转发声明Node
template <class T> class Node; // forward declaration for Node
template <class T> class List {
public:
List();
T get(const int n);
void add(const T element);
....
};
template <class T> class Node {
public :
....
};
....
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)