创建链表插入函数,但代码未运行
Creating Linked list insertion function but the code is not running
无法识别在链表类中创建链表插入函数时的错误编译器给出此" error: qualied -id在'('令牌之前的声明中"但似乎所有的括号都放置正确
#include <iostream>
using namespace std;
void additem();
void deleteitem();
void searchitem(int x);
struct student{
int data;
int * next;
};
student * head;
student * curr;
int main()
{
int x;
cout << "To add item type 1" << endl;
cin >> x;
switch(x)
{
case 1:
additem();
}
return 0;
}
void additem()
{
student * temp;
if(head == NULL)
{
temp = new student;
head = temp;
curr = temp;
temp->next = NULL;
cout << "Enter data" << endl;
cin >> temp->data << endl;
}
else if(head != NULL)
{
temp = new student;
curr->next = temp;
curr = temp;
temp->next = NULL;
cout << "Enter data" << endl;
cin >> temp->data ;
}
else{
break;
}
}
在main
中声明一个类和方法。这是不允许的(嵌套函数)。linkedlist::additem
需要在main之前定义
相关文章:
- 我的代码运行良好,但在游戏循环中中断
- 通过窗口从C++代码运行 WSL 命令
- 如何使用 lldb 查找我的代码运行的位置
- 无法在 VS Code 上使用代码运行程序运行C++文件
- 我的代码运行良好,但现在当尝试将其制作成模板时,我遇到了许多看似无关的错误。这是怎么回事?
- Visual Studio代码运行环境
- 如何从C++代码运行自定义 GPU tensorflow::op?
- 在 ZeroMQ 中绑定订阅者套接字并连接发布者套接字会在代码运行时给出错误.为什么
- 代码运行缓慢
- .NET CORE 2 DLL引用带有C 代码运行时错误
- C++ 中控制台代码运行时的分段错误
- C++ 菜单代码 - 运行另一个类
- 以下代码运行后,如何在程序再次运行之前清除用户声明的变量 empName
- 当我使用此合并排序代码运行时,输出错误
- 有哪些优化技巧可以使我的代码运行得更快
- 使 C 代码能够作为C++代码运行
- 错误代码LNK1561阻止我的代码运行
- 如果我用代码块编译代码,为什么我的代码运行速度更快
- 更改Linux用户从C/C 代码运行时间
- 为什么这段代码运行这么慢