Why can't a function go after Main

前端 未结 8 1864
一向
一向 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 12:50

    You can, but you have to declare it beforehand:

    void myFunction(); // declaration
    
    int main()
    {
       myFunction();
    }
    
    void myFunction(){} // definition
    

    Note that a function needs a return type. If the function does not return anything, that type must be void.

提交回复
热议问题