#ifndef NODE_HPP #define NODE_HPP template class List; // 友元类的前置声明 template class Node { T info; // 数据域 Node *link; // 指针域,注意结点类格式,类模板实例化为类 public: Node() : link{nullptr} {} // 默认构造函数,用于构建头节点 Node(const T &data) : info{data}, link{nullptr} {} // 生成一般结点的构造函数 Node(const Node &) = delete; Node &operator=(const Node &) = delete; void insert_after(Node *p) // 在当前结点后插入一个结点 { p->link = link; link = p; } Node *remove_after() // 删除当前结点的后继结点并返回其地址 { if (link) // 判断节点后是否有节点 { Node *tempP{link}; // 获取后继节点 link = tempP->link; return tempP; } return nullptr; } void print() { std::cout << info << ' '; // 需要info支持插入运算符重载 } T get_info() { return info; } friend class List; // 以List为友元类 }; #endif