设置静态变量时出现以下错误
error: expected primary-expression before '.' token
“GameScene.h”
#ifndef __GAME_SCENE_H__
#define __GAME_SCENE_H__
class Game {
public:
enum InteractionMode {
EDITING,
PLAYING };
static Game::InteractionMode mode;
}
#endif // __GAME_SCENE_H__
“GameScene.cpp”
#include "GameScene.h"
Game *Game::singleton() {
if (_GameSingleton == NULL) {
_GameSingleton = Game::create();
Game::mode = Game::InteractionMode.PLAYING; //error on this line
}
return _GameSingleton;
}
最佳答案
代替
Game::mode = Game::InteractionMode.PLAYING
直接写
Game::mode = PLAYING
另外,由于mode
是static
,你必须在类外定义它,添加:
Game::InteractionMode Game::mode;
关于c++ - 在 cpp 文件中设置静态枚举变量的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15680589/