包含main()Visual Studio定义的两个文件? [英] Two files containing definition of main() Visual Studio?
问题描述
我已经在Visual Studio 2008专业版中创建了一个项目.
I have created a project in Visual Studio 2008 Professional Edition.
该项目为每个作业都包含一个.cpp文件,就像这样...
This project contains one .cpp file for each assignment like this...
[-]Source Files
\
|-- 233.cpp
|-- test.cpp
每个文件都包含main()的定义.
操作:CTRL + F5
Action:CTRL+F5
Error 1 error LNK2005: _main already defined in 233.obj test.obj
Error 2 fatal error LNK1169: one or more multiply defined symbols found
如何编译并查看每个文件的输出?
谢谢.
推荐答案
在一个项目中,不能有2个称为main()的函数.您应该做的是更改函数的名称,然后从一个新的main()函数(将其用作菜单)中调用它们.
You can't have 2 functions called main() in a single project. What you should do is change the names of the functions, and then call them from a new main() function which would function as a menu.
如果将它们做成单独的项目,则可以使用解决方案属性"->启动项目"来切换要运行的项目.
If you make them separate projects, you can switch which one to run with Solution Properties -> Startup Project.
这篇关于包含main()Visual Studio定义的两个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!