I drew a little graph in paint that explains my problem:
But it doesn't seem to show up when I use the <img>
tag after posting?
Here is a direct link: http://i44.tinypic.com/103gcbk.jpg
I drew a little graph in paint that explains my problem:
But it doesn't seem to show up when I use the <img>
tag after posting?
Here is a direct link: http://i44.tinypic.com/103gcbk.jpg
But it doesn't seem to be showing up when I use the img tag after posting?
Here is a direct link: http://i44.tinypic.com/103gcbk.jpg
You need to instantiate the database outside of main(), otherwise you will just declare a local variable shadowing the global one.
GameServer.cpp:
#include GameSocket.h
Database db(1, 2, 3);
int main() {
//whatever
}
The extern is being applied to all the CPP (and resulting OBJ) files, so none of them ever actually instantiate the DB.
Here's one way around this. In Database.h, change the extern Database db
to:
#ifdef INSTANTIATE_DB
Database db;
#else
extern Database db;
#endif
and then in one of your CPP files (Database.cpp would be good, if you have one) add a #define INSTANTIATE_DB
before the #include "Database.h"
.
The problem is the scope of the declaration of db. The code:
extern Database db;
really means "db is declared globally somewhere, just not here". The code then does not go ahead and actually declare it globally, but locally inside main(), which is not visible outside of main(). The code should look like this, in order to solve your linkage problem:
Database db;
int main ()
{
...
}
extern Database db;
void some_function ()
{
...
}