2016-06-09 46 views
3

您看到我一直在嘗試創建一個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_ 
+1

請參閱[this](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)。你需要將'__ENTITY__'改成別的東西。 – juanchopanza

回答

11

"Entity.h"的內容將不會被包括在內的。

變化

#ifdef __ENTITY__ 

#ifndef __ENTITY__ 

BTW:名稱包含雙下劃線或以下劃線後跟一個大寫字母C++中保留的開始,你要小心了。

+1

這是一個保留名稱。 – juanchopanza

+1

好找!一個非常微妙的錯誤。 –

+0

@juanchopanza - 在公平性上,OP首先使用了標識符。 –