Compiler complaining about my singleton class
The compiler is complaining about my singleton class I am creating. It's pretty simple.
Here is the .h file:
Code:
class GAME_MANAGER
{
private:
//Single instance of the GAME_MANAGER class
static GAME_MANAGER *gameManagerInstance;
//Constructors and assignment operator - private
GAME_MANAGER ( ) { };
GAME_MANAGER ( const GAME_MANAGER © ) { };
void operator = ( const GAME_MANAGER &rhs ) { };
public:
static GAME_MANAGER *GetInstance ( );
};
Here is the cpp file:
Code:
#include "game_manager.h"
GAME_MANAGER *GAME_MANAGER::gameManagerInstance = NULL;
static GAME_MANAGER::GAME_MANAGER *GetInstance ( )
{
if ( !gameManagerInstance )
{
gameManagerInstance = new GAME_MANAGER();
}
return gameManagerInstance;
}
As far as I know this is the way singletons are supposed to be done in C++, but it is really complaining at me a lot.
The errors are as follows:
Quote:
game_manager.cpp||In function `GAME_MANAGER* GetInstance()':|
game_manager.cpp|7|error: `gameManagerInstance' was not declared in this scope|
inc\game_manager.h|25|error: `GAME_MANAGER::GAME_MANAGER()' is private|
game_manager.cpp|9|error: within this context|
game_manager.cpp|12|error: `gameManagerInstance' was not declared in this scope|
||=== Build finished: 4 errors, 0 warnings ===|
Any ideas what is going wrong?
Oh...I am using Code::Blocks, and the compiler appears to be GCC 3.4.5.
Thanks