这是我在这里的第一个问题。
在编写一些代码时,我收到来自g++的错误:“实体未在此范围内声明”,在此上下文中:
#ifndef Psyco2D_GameManager_
#define Psyco2D_GameManager_
#include <vector>
#include "Entity.h"
namespace Psyco2D{
class GameManager{J
private:
std::vector<Entity> entities;
};
}
#endif这是Entity.h的内容:
#ifndef Psyco2D_Entity_
#define Psyco2D_Entity_
#include <string>
#include "GameManager.h"
#include "EntityComponent.h"
namespace Psyco2D{
class Entity{
friend class GameManager;
private:
/* Identificatore */
std::string _name;
/* Components list */
std::map<const std::string, EntityComponent*> components;
protected:
Entity(const std::string name);
public:
inline const std::string getName() const{
return this->_name;
}
void addComponent(EntityComponent* component, const std::string name);
EntityComponent* lookupComponent(const std::string name) const;
void deleteComponent(const std::string name);
};
}
#endif如果我使用std::vector<class Entity>而不是std::vector<Entity>,它可以工作。
为什么?
感谢所有=)
发布于 2010-07-25 05:59:39
假设第一个代码片段是GameManager.h的一部分,那么您就有了一个循环标头依赖项。我相信您可以通过将Entity.h中的GameManager.h include改为class GameManager;来修复此问题。
此外,正如GMan所指出的,实体位于名称空间中,您需要使用名称空间名称来限定实体。
发布于 2010-07-25 05:50:49
不需要声明"class Entity“,就可以使用它来移除eeco2D-namespace。
https://stackoverflow.com/questions/3326717
复制相似问题