C++中main函数的返回值类型是什么
本篇内容介绍了“C++中main函数的返回值类型是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
F.46:main函数的返回值类型是整数
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.
这是语言本身的准则,但是由于通过“语言扩展”的方式违反该准则的情况非常常见,因此有必要提醒。将main函数(程序唯一的全局main函数)定义为void会限制移植性。
Example(示例)
void main() { /* ... */ }; // bad, not C++
int main()
{
std::cout << "This is the way to do it\n";
}
Note(注意)
We mention this only because of the persistence of this error in the community.
我们提醒这一点只是因为在社区中存在对这个错误的坚持。
Enforcement(实施建议)
-
The compiler should do it
编译器会检查。
-
If the compiler doesn't do it, let tools flag it
如果编译器不检查,让工具检查。
“C++中main函数的返回值类型是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!