Reputation: 47
I am using Visual studio 2019 for learning C++. Every time I am crating project for each program. Is it possible to crate and run multiple main source file on Visual Studio like Java on Eclipse/Netbeans/IntellijIdea? Thank you.
Upvotes: 0
Views: 3331
Reputation: 1692
The short answer "You can't and you can".
main() is called an entry point. In Java you can have main()
in every class because each class can be self-contained in theory.
C++ doesn't work like this because at the end every thing get linked to a single executable.
If you want to have multiple entry points You need to:
Upvotes: 1
Reputation: 53
There is two ways of doing it. Either you use cmake
, more info here
or
you put the main functions in separate namespaces and then define, which one do you want to run. example here
Upvotes: 1