Is main() overloaded in C++?

后端 未结 6 1703
再見小時候
再見小時候 2020-11-29 01:51

2 valid versions of main() exist in C++:

int main()  // version 1
int main(int argc, char **argv)  // version 2

B

6条回答
  •  伪装坚强ぢ
    2020-11-29 02:07

    The standard says that main cannot be overloaded. It isn't mangled, and you cannot have two functions with the same unmangled name. This will cause a linking failure, I guess, but a compiler could want to add explicit checks in order to give clearer error messages.

    int main(int argc, char **argv) and int main() should be the preferred signatures for it, but compilers are free to accept a main with different parameters.

提交回复
热议问题