未定义的“操作”参考

时间:2015-12-27 17:36:03

标签: c++ c

当我用代码块编译这个程序时,我得到了未定义的“操作”引用。我只包含了显示错误的程序的一部分。我该如何解决这个错误?

#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)
            {
                ---------
                    ---------
            }
        }
     }
}

2 个答案:

答案 0 :(得分:1)

如果按照显示的消息进行操作,则需要operations中调用之前声明函数main的原型。

void operations(void);
int main(void){
...
// then your code

答案 1 :(得分:1)

您不应在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;
       }

    }
}