首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >另一个“x未在此作用域中声明”

另一个“x未在此作用域中声明”
EN

Stack Overflow用户
提问于 2010-07-25 04:16:07
回答 2查看 2.2K关注 0票数 2

这是我在这里的第一个问题。

在编写一些代码时,我收到来自g++的错误:“实体未在此范围内声明”,在此上下文中:

代码语言:javascript
复制
#ifndef Psyco2D_GameManager_
#define Psyco2D_GameManager_

#include <vector>
#include "Entity.h"

namespace Psyco2D{
    class GameManager{J
    private:
        std::vector<Entity> entities;
    };
}

#endif

这是Entity.h的内容:

代码语言:javascript
复制
#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>,它可以工作。

为什么?

感谢所有=)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-07-25 05:59:39

假设第一个代码片段是GameManager.h的一部分,那么您就有了一个循环标头依赖项。我相信您可以通过将Entity.h中的GameManager.h include改为class GameManager;来修复此问题。

此外,正如GMan所指出的,实体位于名称空间中,您需要使用名称空间名称来限定实体。

票数 4
EN

Stack Overflow用户

发布于 2010-07-25 05:50:49

不需要声明"class Entity“,就可以使用它来移除eeco2D-namespace。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3326717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档