two main in visual c++
ho开发者_开发问答w can I run two main Visual Studio (Visual C ++).. I would like to have a main that represents the server and a main that is the client and run them running on two different consoles. how can I do?
It is possible to create two separate projects within a single Visual Studio solution. Each one can be an independent console application with its own main
entrypoint. However, the simplest way to do that if you are wanting to debug both projects at the same time is to open two separate instances of Visual Studio, one with the client solution and one with the server.
Create two functions:
int server_main( int argc, char* argv[] );
int client_main( int argc, char* argv[] );
in the actual
int main( int argc, char* argv[] )
check for a command line argument ( --server or --client ) and then depending on which one is present, delegate to server_main or client_main.
When it comes to debugging, do what they've already suggested which is run two different instances of VS.
Everybody else is right in pointing out that there can be only one "main", but I think this answers what you actually wanted to ask.
You can't have two main
functions. Either have separate builds with ifdef
guards or a command line argument.
You have to create two separate programs. Each program will have its separate main()
function.
Create a library with the shared code (assuming that's what you're after here) and create two separate binaries, one for the server and one for the client.
精彩评论