Two main functions

前端 未结 8 850
孤独总比滥情好
孤独总比滥情好 2020-12-19 10:20

Can we have two main() functions in a C++ program?

8条回答
  •  庸人自扰
    2020-12-19 10:40

    Only one function can be named main outside of any namespace, just as for any other name. If you have namespaces foo and bar (etc) you can perfectly well have functions named foo::main, bar::main, and so on, but they won't be treated as anything special from the system's point of view (only the function named main outside of any namespace is treated specially, as the program's entry point). Of course, from your main you could perfectly well call the various foo::main, bar::main, and so on.

提交回复
热议问题