您看到我一直在嘗試創建一個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_
請參閱[this](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)。你需要將'__ENTITY__'改成別的東西。 – juanchopanza