开发者

Singleton Implemenatatio Linker Error

class Game
{
public:
    //! Returns the only instance of the game object
    static shared_ptr<Game> GetGameInstance();
    //! Function with continous loop for game play
    void GamePlay();
    //! The hidden constructor
    ~Game();

private:
    //! The hidden constructor
    Game();
    static shared_ptr<Game> _game;
};



//.cpp file

#include "Game.h"

shared_ptr<Game> Game::_game;

shared_ptr<Game> Game::GetGameInstance()
{
    if(_game == NULL)
    {
        _game.reset(new Game);
    }
    return _game;
}

void Game::GamePlay()
{
    shared_ptr<Graphics> myGameGraphics;

    while(!myGameGraphics->UserForcedExit())
    {
        myGameGraphics->drawMaze();
    }

}

Game::~Game()
{

}

I have the code above,but the compilation gives me a linker error:

Game.obj : error LNK2019: unresolved external symbol "private: __thiscall Game::Game(void)" (??0Game@@AAE@XZ) referenced in function "public: static class boost::shared_ptr __cdecl Game::GetGameInstance(void)" (?GetGameInstance@Game@@SA?AV?$shared_ptr@VGame@@@boost@@XZ)

Can anyone please help...开发者_开发技巧


try this:

shared_ptr<Game> Game::GetGameInstance()
{
    if(_game = NULL)
        _game = shared_ptr<Game>(new Game);

    return _game;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜