结构因某种原因无法识别成员

时间:2011-12-03 16:29:14

标签: c++ struct

运行此代码时,它会给我一个奇怪的错误。我有一个名为scene的类,而scene有一个名为“commands”的数组成员。我有一个名为cGame的结构,它有一个名为current scene的成员。

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]' 

1 个答案:

答案 0 :(得分:1)

错误大约是scene_container。你确定这是一个可以用[]索引的数组/向量/ ...吗? current_scene是否是用作索引的正确类型?