本文介紹了為什么函數不能在 Main 之后的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
為什么我不能在main之后放一個函數,visual studio無法構建程序.這是 C++ 的怪癖還是 Visual Studio 的怪癖?
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?
例如
int main()
{
myFunction()
}
myFunction(){}
會產生 main 不能使用 myFunction 的錯誤
will produce an error that main cannot use myFunction
推薦答案
可以,但必須事先聲明:
You can, but you have to declare it beforehand:
void myFunction(); // declaration
int main()
{
myFunction();
}
void myFunction(){} // definition
請注意,函數需要返回類型.如果函數不返回任何內容,則該類型必須為 void
.
Note that a function needs a return type. If the function does not return anything, that type must be void
.
這篇關于為什么函數不能在 Main 之后的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!