运行这段代码时,它给了我一个奇怪的错误。我有一个名为场景的类,场景有一个名为“命令”的数组成员。我有一个名为 cGame 的结构,它有一个名为当前场景的成员。
struct MainGameLoop{
void init(){
this->cGame.init();
}
game_struct cGame;
void begin_cipher(string input){
if(input == "save" || input == "SAVE"){
cGame.cPlayer.save_game();
cout << "\n\nGame saved...";
}
if(input == "back" || input == "BACK"){
cGame.go_back();
}
if(input != "back" && input != "BACK" && input != "save" && input != "SAVE"){
bool is_recognized_scene_command;
for(int c = 0; c < 11 ; c++){
if(input == cGame.scene_container[this->cGame.current_scene].commands[c]){
cout << "\n\nREQUEST IS RECOGNIZED BY SCENE...";
}
else{
cout << "REQUEST IS NOT RECOGNIZED!";
}
}
}
}
};
这段代码给出了错误:
279 C:\Dev-Cpp\the_main_mage.cpp no match for 'operator[]' in '((MainGameLoop*)this)->MainGameLoop::cGame.game_struct::scene_container[((MainGameLoop*)this)->MainGameLoop::cGame.game_struct::current_scene]'
最佳答案
错误是关于scene_container
。你确定这是一个数组/vector/...可以用 []
索引吗? current_scene
是用作索引的正确类型吗?
关于c++ - 由于某种原因结构无法识别成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8369082/