c++ - C++中的链表节点

标签 c++ linked-list

我正在学习一本关于数据结构的书,并在链表示例中编译了他们的节点,但我收到此错误:

 and Everything.cpp|7|error: expected unqualified-id before "int"|
 and Everything.cpp|7|error: expected `)' before "int"|
||=== Build finished: 2 errors, 0 warnings ===|

节点的代码是:

typedef struct Node
{
    struct Node(int data)    //Compile suggest problem is here
    {
        this-> data = data;
        previous = NULL;
        next = NULL;
    }
    int data;
    struct Node* previous;
    struct Node* next;
} NODE;

我不熟悉结构,我正在使用 Code::blocks 进行编译。有谁知道怎么了?

最佳答案

代码示例错误。构造函数声明前不应该有关键字struct。应该是:

typedef struct Node
{
    Node(int data)  // No 'struct' here
    {
        this-> data = data;
        previous = NULL;
        next = NULL;
    }
    int data;
    struct Node* previous;
    struct Node* next;
} NODE;

关于c++ - C++中的链表节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/918702/

相关文章:

c++ - 从dll c++获取字符串

c++ - "typename"和 "template"关键字 : are they really necessary?

c - C语言链表中的节点

c++ - 如何在每个元素中使用自定义字符串设置 std::vector<std::string>

c++ - 谷歌 pnacl : how to use the compiler/linker

c++ - SendInput() 不是 "sending"正确的移位字符吗?

c - 将标准输入的整数输入插入链表

c++ - C - 正在使用变量 'p_prvy' 而未初始化

c - 段错误和链表的未知问题

c - 这段代码如何在链表中查找循环?