Why can't a function go after Main

前端 未结 8 1841
一向
一向 2020-12-09 12:37

Why can\'t I put a function after main, visual studio cannot build the program. Is this a C++ quirk or a Visual Studio quirk?

eg.

int main()
{
   myF         


        
相关标签:
8条回答
  • 2020-12-09 13:08

    you have to forward declare a function so main can know that there is some.

    void myFunction();
    
    int main()
    {
       myFunction();
    }
    
    void myFunction(){}
    

    Don't forget about putting ; after each command.

    0 讨论(0)
  • 2020-12-09 13:10

    You have to declare the function before.

    void myFunction();
    
    int main()
    {
        myFunction()
     }
    
     myFunction(){}
    
    0 讨论(0)
提交回复
热议问题