当我用代码块编译该程序时,会得到未定义的对“操作”的引用。我只包含了显示错误的程序的一部分。如何解决此错误?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
---------------------
---------------------
while(1)
{
printf("Choose from one of the following options :\n");
printf("1. XXX\n 2. YYY\n 3. ZZZ\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
case 2:
case 3:
case 4:operations();
return 0;
break;
default: printf("Wrong option choose again\n");
return 1;
}
}
void operations()
{
while(1)
{
printf("Choose from one of the following options :\n");
printf("1. XXX\n2. YYY\n3. ZZZ\n");
scanf("%d",&choice_of_options);
switch(choice_of_options)
{
---------
---------
}
}
}
}
最佳答案
您不应该在operations
函数中实现main
:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void operations()
{
while(1)
{
printf("Choose from one of the following options :\n");
printf("1. XXX\n2. YYY\n3. ZZZ\n");
scanf("%d",&choice_of_options);
switch(choice_of_options)
{
---------
---------
}
}
}
int main()
{
---------------------
---------------------
while(1)
{
printf("Choose from one of the following options :\n");
printf("1. XXX\n 2. YYY\n 3. ZZZ\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
case 2:
case 3:
case 4:operations();
return 0;
break;
default: printf("Wrong option choose again\n");
return 1;
}
}
}
关于c++ - 未定义对“操作”的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34483000/