C++ 允许以下两种 main 定义:
int main() { }
int main(int argc, char* argv[]) { }
它还允许char*[]
被命名为char**
和argc
和argv
无论程序员想要什么。但是,它是否也允许:
int main(int, char*[]) { }
这和上面的例子一样吗?是否严格符合?请注意,我不关心它是否可以在您最喜欢的编译器中编译,我只询问标准。
最佳答案
是的,正如@Captain Obvlious 所说,C++ 只关心参数的类型。 C++ 标准委员会公开发表的论文 here供大家引用。
3.6.1 主要功能
- An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined. All implementations shall allow both
— a function of () returning int and
— a function of (int, pointer to pointer to char) returning int
关于c++ - main() 中的无名参数是否严格符合要求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32194151/