gpt4 book ai didi

c++ - 在 cpp 文件中设置静态枚举变量的正确方法

转载 作者:搜寻专家 更新时间:2023-10-30 23:59:36 31 4
gpt4 key购买 nike

设置静态变量时出现以下错误

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

另外,由于modestatic,你必须在类外定义它,添加:

Game::InteractionMode Game::mode;

关于c++ - 在 cpp 文件中设置静态枚举变量的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15680589/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com