您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“C++中main函數(shù)的返回值類型是什么”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
F.46:main函數(shù)的返回值類型是整數(shù)
Reason(原因)
It's a language rule, but violated through "language extensions" so often that it is worth mentioning. Declaring main
(the one global main
of a program) void
limits portability.
這是語言本身的準(zhǔn)則,但是由于通過“語言擴展”的方式違反該準(zhǔn)則的情況非常常見,因此有必要提醒。將main函數(shù)(程序唯一的全局main函數(shù))定義為void會限制移植性。
Example(示例)
void main() { /* ... */ }; // bad, not C++
int main()
{
std::cout << "This is the way to do it\n";
}
We mention this only because of the persistence of this error in the community.
我們提醒這一點只是因為在社區(qū)中存在對這個錯誤的堅持。
Enforcement(實施建議)
The compiler should do it
編譯器會檢查。
If the compiler doesn't do it, let tools flag it
如果編譯器不檢查,讓工具檢查。
“C++中main函數(shù)的返回值類型是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。