我收到“找不到标识符”错误
这是我第一次尝试创建一个基本列表(我在学校需要这个),但我得到了一个奇怪的错误。
这是脚本:
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
using namespace System;
using namespace System::Threading;
struct nod
{
int info;
nod *leg;
};
int n, info;
nod *v;
void main()
{
....
addToList(v, info); //I get the error here
showList(v); //and here
}
void addToList(nod*& v, int info)
{
nod *c = new nod;
c->info=info;
c->leg=v;
v=c;
}
void showList(nod* v)
{
nod *c = v;
while(c)
{
cout<<c->info<<" ";
c=c->leg;
}
}
确切的错误是: 错误C3861:'addToList':找不到标识符
我不知道为什么我得到这个...抱歉,如果这是一个愚蠢的问题,但我对此很陌生。感谢您的理解。
This is my first attempt to create a basic list (i need this at school) and i get a strange error.
This is the script:
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
using namespace System;
using namespace System::Threading;
struct nod
{
int info;
nod *leg;
};
int n, info;
nod *v;
void main()
{
....
addToList(v, info); //I get the error here
showList(v); //and here
}
void addToList(nod*& v, int info)
{
nod *c = new nod;
c->info=info;
c->leg=v;
v=c;
}
void showList(nod* v)
{
nod *c = v;
while(c)
{
cout<<c->info<<" ";
c=c->leg;
}
}
The exact error is:
error C3861: 'addToList': identifier not found
I dont know why I get this... sorry if it is a stupid question but i am very new at this. Thanks for understanding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要在实现之前提出一个前向声明才能使用该方法。将其放在 main 之前:
在 C/C++ 中,方法只能在声明后使用。要允许不同方法之间的递归调用,您可以使用前向声明以允许使用函数/将向前实施的方法。
you need to put a forward declaration to use a method before it's implementation. Put this before main :
In C/C++ a method should be used only after it's declaration. To allow recursive call between different methods you can use forward declarations in order to allow the use of a function/method that will be forward implemented.
标识符必须在使用前声明。将
addToList
的声明和定义移至文本文件的前面。因此:
Identifiers must be declared before they are used. Move your declaration and definition of
addToList
earlier in the text file.Thus:
尝试在 main 上方声明 addToList:
void addToList(nod*& v, int info);
对于 showList 类似。编译器在使用函数之前需要查看函数的声明。
Try declaring addToList above main:
void addToList(nod*& v, int info);
Similarly for showList. The compiler needs to see a declaration of the function before it can use it.
尝试将
showList()
和addToList()
声明放在main()
之前。Try placing the declarations of
showList()
andaddToList()
beforemain()
.