Can I call the main method in C/C++ from other functions. it seems to work but I do not know if it is a good software design in c++. please tell me the pros and cons ? Thank you.
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
In C you can. In C++ you can't.
Quoting the C++ standard (§3.6.1.3):
There's nothing in the C standard forbidding calling
main
.Whether or not calling
main
is good design is quite opinion-based, but usually one would be better off using a loop instead.According to C++ standard
You've already determined it is possible. However, it makes your entire program recursive. It also could make your code a little harder to understand.
So it's really hard for me to imagine any pros for this.