int
is the return type for main()
F.46:main函数的返回值类型是整数
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会限制移植性。
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.
我们提醒这一点只是因为在社区中存在对这个错误的坚持。
觉得本文有帮助?请分享给更多人。
关注【面向对象思考】,轻松学习每一天!
有任何疑问,欢迎留言提问或讨论。
面向对象设计,面向对象编程,面向对象思考!