Jac*_*koz 3 c++ macros include-guards
你看,我一直在尝试创建一个std::vector
包含Entity
类中类的IState
类.这两个类都是接口.
错误是
"实体"未在此范围内声明
并指出:
protected:
std::vector <Entity*> ent_map;
Run Code Online (Sandbox Code Playgroud)
在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__
Run Code Online (Sandbox Code Playgroud)
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_
Run Code Online (Sandbox Code Playgroud)
son*_*yao 11
内容"Entity.h"
将不包括在内.
更改
#ifdef __ENTITY__
Run Code Online (Sandbox Code Playgroud)
至
#ifndef __ENTITY__
Run Code Online (Sandbox Code Playgroud)
BTW:名称包含双下划线或以下划线开头,后跟大写字母在C++中保留,您需要注意它.