C++中链表的问题
Problems with Linked list in C++
我对C++完全陌生,正为一个简单的问题伤透脑筋。我正在尝试实现一个具有三个节点的简单链表。这是我的代码:
#include<iostream>
using namespace std;
struct node(){
int data;
struct node* next;
};
struct node* BuildOneTwoThree() {
struct node* head = NULL;
struct node* second = NULL;
struct node* third = NULL;
head = new node;
second = new node;
third = new node;
head->data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;
return head;
};
问题显然是,为什么它不编译?:(
提前感谢您的帮助!
从结构声明中删除"()"。你的编译器应该告诉你的。
更换
struct node(){
int data;
struct node* next;
};
带有
struct node{
int data;
struct node* next;
};
在结构声明之后的额外语法导致了错误。后者是在C++中声明struct
或class
的正确方法。
struct
的声明有一对多余的括号。当你删除它们时,这应该是可以的:
struct node{
int data;
struct node* next;
};
()
应该写在函数后面,而不是结构/类名后面。
相关文章:
- 链表指针问题
- 我对数据结构、双向链表有一些问题
- 在解决链表问题时创建一个额外的节点是一个好习惯吗?
- Sinlge 链表,C++,删除所有和搜索功能的问题
- C++ 从链表中删除项目时出现问题
- 如何修复我的链表读数不一致的问题?
- C++中链表实现的问题
- 双向链表问题 - 包含项目但不显示
- 嵌套的类成员变量不可访问.链表设置.V、下一个和新的问题
- 在链表中的某个点插入时出现问题,C++中的继承函数
- cpp 中的以下链表程序有什么问题?
- 单个链表,节点插入最低到最高节点值的问题
- 我在让我的代码输出整个链表时遇到问题.它只是输出我修改过的一些文本文件,而不是整个东西
- 双向链表问题(特别是复制构造函数和删除函数)
- 我在双链表上的此打印功能时遇到问题
- 我在显示链表时遇到问题
- 尝试在链表程序的末尾进行更简单的插入.小问题需要帮助
- 节点和链表问题
- c++理解问题-链表和堆栈
- C++语法问题(链表)