指向另一个类中不同类的C++指针

指向另一个类中不同类的C++指针,c++,class,pointers,C++,Class,Pointers,我一直在搜索文档并检查我的类给出的示例代码,但我不知道这里出了什么问题。我正在尝试构建一个链表结构,需要能够指向节点的指针,但似乎无法正确初始化节点。节点彼此指向很好,这是一个包含第一个/最后一个/当前指针的总体类,它给我带来了问题 下面的代码在我尝试创建节点类的指针时给了我一系列错误。我在“;”前面得到C2238个意外标记第19、20和21行以及C2143中缺少“;”在“*”和C4430之前缺少类型说明符。。。对于第19行、第20行和第21行,请再次单击linkedList的受保护部分 tem

我一直在搜索文档并检查我的类给出的示例代码,但我不知道这里出了什么问题。我正在尝试构建一个链表结构,需要能够指向节点的指针,但似乎无法正确初始化节点。节点彼此指向很好,这是一个包含第一个/最后一个/当前指针的总体类,它给我带来了问题

下面的代码在我尝试创建节点类的指针时给了我一系列错误。我在“;”前面得到C2238个意外标记第19、20和21行以及C2143中缺少“;”在“*”和C4430之前缺少类型说明符。。。对于第19行、第20行和第21行,请再次单击linkedList的受保护部分

template <class Type>
class linkedList
{
public:
    //constructors
    linkedList();

    //functions
    void insertLast(Type data);             //creates a new node at the end of the list with num as its info
    void print();                           //steps through the list printing info at each node
    int length();                           //returns the number of nodes in the list
    void divideMid(linkedList sublist);     //divides the list in half, storing a pointer to the second half in the private linkedList pointer named sublist

    //deconstuctors
    ~linkedList();
protected:
    node *current;                          //temporary pointer
    node *first;                            //pointer to first node in linked list
    node *last;                             //pointer to last node in linked list
    bool firstCreated;                      //keeps track of whether a first node has been assigned
private:
};

template <class Type>
struct node
{
    Type info;
    node<Type> *next;
};

按如下方式更改受保护的部分也会保留C2238和C4430错误,但会将C2143更改为缺少“;”在“之前,需要在linkedList之前为节点进行转发声明:


请查看工作版本。

您知道如何编写非模板链接列表吗?
    node<Type> *current;                            //temporary pointer
    node<Type> *first;                              //pointer to first node in linked list
    node<Type> *last;                               //pointer to last node in linked list
template <class Type>
struct node;