c++ - 由于某种原因结构无法识别成员

标签 c++ struct

运行这段代码时,它给了我一个奇怪的错误。我有一个名为场景的类,场景有一个名为“命令”的数组成员。我有一个名为 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/

相关文章:

c++ - 如何使用 Libwebp 从 Webp 解码和编码?

c++ - 谷歌模拟 : How to test this code?

c++ - 单例模式解释

c++ - 在执行时在布局中添加自定义小部件

c++ - 为什么这两个 high(64bx64b) 函数给出不同的结果?

c - 各自领域的学习结构和算术

arrays - 如何在结构中附加 slice

iphone - NSUndoManager 和 GLKit

c - 释放链表中的节点

c++ - 检查结构中的模板类型