是主函数在C ++或C中可调用 [英] Is the main function callable in C++ or C
本文介绍了是主函数在C ++或C中可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以从其他函数调用C / C ++中的main方法。它似乎工作,但我不知道它是否是一个很好的软件设计在c ++。请告诉我的优点和缺点?
谢谢。
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.
推荐答案
在C中可以。在C ++中不能。
In C you can. In C++ you can't.
引用C ++标准(§3.6.1.3):
Quoting the C++ standard (§3.6.1.3):
函数
main
不得在程序中使用。
C标准中禁止调用 main
。
无论是否调用主
是好的设计是相当意见为基础的,但通常一个会更好的使用循环代替。
Whether or not calling main
is good design is quite opinion-based, but usually one would be better off using a loop instead.
这篇关于是主函数在C ++或C中可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文