When looking at some existing code for a web server, I see that there’s a main.cc file and another server.h and server.cc pair for the server class.
// main.cc
#include "server.h"
int main() {
foo::server = new foo::Server();
server->Serve(); // runs forever
}
// server.cc
namespace foo {
Server *server;
// class member definitions ...
}
Is there a good reason not to just define foo::Server *server in main?
What are the pros and cons of this coding style?
EDIT
For maintenance. It’s intuitive that you have the definition of
foo::serverinserver.cc. If you only have one variable, the benefit is not directly visible. But say you have dozens of variables. With this style, you know exactly where to look for the definition.