c++ - 模板化类声明 C++

标签 c++ class templates declaration

我认为这只是一个语法问题。但无论我怎么做,我都会不断收到编译器错误。我正在使用基于节点的列表类,但不知道如何编写声明 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/

相关文章:

c++ - 使用索引的随机访问迭代器 - 示例

c++ - Qt Drop 事件未触发

php - 设计 - 整合我的 PHP 文件?

Java Swing 应用程序不再工作

c++ - 模板类创建

c++ - [ranges.subrange] 中 `iterator-sentinel-pair` 概念的目的是什么?

c++ - 修整 UTF8 缓冲区

c++ - 模板中的关键字 "typename"

c++ - 模板上的神秘错误

c++ - 如何在类型依赖于派生类的基模板类中声明成员?