单例实现链接器错误
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()
{
}
我有上面的代码,但编译给了我一个链接器错误:
Game.obj : error LNK2019: unresolved external symbol "private: __thiscall Game::Game(void)" (??0Game@@AAE@XZ) 在函数中引用“公共:静态类 boost::shared_ptr __cdecl Game::GetGameInstance(void)” (?GetGameInstance@Game@@SA?AV?$shared_ptr@VGame@@@boost@@XZ)
任何人都可以帮忙吗...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
try this: