c – 错误“未在范围中声明”但带有接口
发布时间:2020-12-16 10:13:08 所属栏目:百科 来源:网络整理
导读:您看到我一直在尝试创建一个std :: vector,其中包含IState类中的Entity类.这两个类都是接口. 错误是 ‘Entity’ was not declared in this scope 并指出: protected: std::vector Entity* ent_map; 在IState.h中 我一直在努力解决它.一旦我在IState.h中做了
您看到我一直在尝试创建一个std :: vector,其中包含IState类中的Entity类.这两个类都是接口.
错误是
并指出: protected: std::vector <Entity*> ent_map; 在IState.h中 我一直在努力解决它.一旦我在IState.h中做了一个前向声明,但是一旦我做了并尝试使用向量,它就会发出它是一个不完整的类,所以我回到原点. 有任何想法吗? Entity.h #ifdef __ENTITY__ #define __ENTITY__ #include <iostream> #include <SDL.h> class Entity { public: virtual ~Entity(); virtual void load(const char* fileName,std::string id,SDL_Renderer* pRenderer) = 0; virtual void draw() = 0; virtual void update() = 0 ; virtual void clean() = 0; /*void int getX() { return m_x;} void int getY() { return m_y;} void std::string getTexID {return textureID;} */ }; #endif // __ENTITY__ IState.h #ifndef IState_ #define IState_ #include "Entity.h" #include <vector> class IState { public : virtual ~IState(); virtual void update() = 0; virtual void render(SDL_Renderer* renderTarget) = 0; virtual bool onEnter() = 0; virtual bool onExit() = 0; virtual void handleEvents(bool* gameLoop,SDL_Event event) = 0; virtual void resume() = 0; virtual std::string getStateID() = 0; virtual void setStateID(std::string id) = 0; protected: std::vector <Entity*> ent_map; }; #endif // IState_ 解决方法
“Entity.h”的内容根本不包括在内.
更改 #ifdef __ENTITY__ 至 #ifndef __ENTITY__ BTW:名称包含双下划线或以下划线开头,后跟C中保留的大写字母,您需要注意它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |