我已经创建了这段代码
class Game{
static SDL_Surface* screen;
public:
//Initiate Game(SDL_Graphics, folder for output.....)
static void initialize();
static void initializeScreen();
};
void Game::initializeScreen()
{
Game::screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_DOUBLEBUF |SDL_HWSURFACE |SDL_SWSURFACE);
SDL_Init(SDL_INIT_VIDEO);
Game::screen == NULL ? printf("SDL_Init failed: %s\n", SDL_GetError()):printf("SDL_Init initialized\n");
SDL_WM_SetCaption("SDL Animation", "SDL Animation");
}
它编译但我得到 e 链接器错误,我该如何解决这个问题?
1>game.obj : error LNK2001: unresolved external symbol "private: static struct SDL_Surface * Game::screen" (?screen@Game@@0PAUSDL_Surface@@A)
编辑:这就是我修复它的方式,在 game.cpp 中添加了这个
SDL_Surface* Game::screen;
在任何功能之外*