我认为这只是一个语法问题。但无论我怎么做,我都会不断收到编译器错误。我正在使用基于节点的列表类,但不知道如何编写声明 header 。我在哪里放置前向列表类声明等?我只是不知道如何设置它。以下是整个声明标题:
#include <iostream>
using namespace std;
class List;
template <typename T>
class Node{
private:
Node(T, Node*);
T data;
Node* next;
friend class List<T>;
friend ostream& operator<<(ostream&, const List<T>&);
};
class List{
public:
List(int = 0);
List(const List&);
~List();
bool gotoBeginning();
bool gotoEnd();
bool gotoNext();
bool gotoPrior();
bool insertAfter(T);
bool insertBefore(T);
bool remove(T&);
bool replace(T);
bool getCursor(T&) const;
bool empty() const;
bool full() const;
bool clear();
List<T>& operator=(const List&);
friend ostream& operator<<(ostream&, const List<T>&);
bool operator==(const List&) const;
private:
Node* head;
Node* cursor;
};
最佳答案
改成
template <class T>
class List
并将 T 类型添加到节点声明
Node<T>* head;
Node<T>* cursor;
关于c++ - 模板化类声明 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20168711/