“符号‘地图’”无法解决”在命名空间中

发布于 2024-12-07 08:53:51 字数 1044 浏览 1 评论 0 原文

你好!

我目前正在开发一个游戏引擎。尽管我才刚刚开始,但我已经遇到了问题。

我有这样的代码:

#ifndef INSTANS_H_
#define INSTANS_H_
#include <map>
#include "Core/Version.h"
#include "Core/Window.h"
#include "Core/Component.h"
#include "Core/Game.h"

namespace Instans
{
    class Window;
    class Component;

    class Engine
    {
    public:
        Engine();
        ~Engine();

        void AddComponent(char* name, Component* component, int priority = 10);
        void RemoveComponent(char* name);

        void SetFramerateLimit(int limit);

        int GetFramerate();
        int GetFramerateLimit();

        void Run(char* title, int width, int height);
        void Load();

        void Update();
        void Render();

        void Release();
    protected:
    private:
        Window* _window;

        // Game, managers etc.
        std::map<int, char*, Component*> _components;
    };
};
#endif

即使我已经包含了 ,Eclipse 也会给我以下错误:

Symbol 'map' 无法解析 Instans.h

可能是什么原因?

Hello!

I am currently developing an game engine. Even though I only just started, I have already run into a problem.

I have this code:

#ifndef INSTANS_H_
#define INSTANS_H_
#include <map>
#include "Core/Version.h"
#include "Core/Window.h"
#include "Core/Component.h"
#include "Core/Game.h"

namespace Instans
{
    class Window;
    class Component;

    class Engine
    {
    public:
        Engine();
        ~Engine();

        void AddComponent(char* name, Component* component, int priority = 10);
        void RemoveComponent(char* name);

        void SetFramerateLimit(int limit);

        int GetFramerate();
        int GetFramerateLimit();

        void Run(char* title, int width, int height);
        void Load();

        void Update();
        void Render();

        void Release();
    protected:
    private:
        Window* _window;

        // Game, managers etc.
        std::map<int, char*, Component*> _components;
    };
};
#endif

Even though I have included , Eclipse gives me the following error:

Symbol 'map' could not be resolved Instans.h

What could be the cause?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

屌丝范 2024-12-14 08:53:51

正确的限定名称是 ::std::map,因为您已经位于其他命名空间中。

The correctly qualified name is ::std::map, since you're already in some other namespace.

冷弦 2024-12-14 08:53:51

map 的第三个参数是比较函数类型,而不是第三个包含的数据类型。很可能这就是导致您出现问题的原因。

我不太清楚您要做什么,但如果您尝试将 int/string 复合键映射到组件,您可以使用:

std::map,组件*>

The third parameter to map is a comparison function type, not a third contained data type. Chances are that's what's causing your problem.

I can't quite tell what you're trying to do but if you're trying to map an int/string composite key to a Component you could use:

std::map<std::pair<int, std::string>, Component*>

悸初 2024-12-14 08:53:51

要映射的第三个模板参数应该是比较函数。我猜你正在尝试从 int -> 映射(字符*,组件)。您需要将 char 和 Component* 包装成一个结构或一对......

typedef std::pair<char*, Component*> CharAndComponentPair;
typedef std::map<int, CharAndComponentPair> ComponentMap;

ComponentMap _components;

The third template parameter to map should be a comparison function. I'm guessing you are trying to map from int -> (char *, Component ). You'll need to wrap the char and Component* into a struct or a pair...

typedef std::pair<char*, Component*> CharAndComponentPair;
typedef std::map<int, CharAndComponentPair> ComponentMap;

ComponentMap _components;
眼眸里的那抹悲凉 2024-12-14 08:53:51

如果这是 Eclipse 问题而不是编译问题,那么问题在于从索引器的角度来看缺少一堆包含目录。

添加以下内容对我有用,但可能取决于它们实际存在的特定设置:

/usr/include/c++/4.6.1
/usr/include/                
/usr/include/c++             
/usr/include/c++/4.6         
/usr/include/x86_64-linux-gnu
/usr/include/asm-generic
/usr/include/c++/4.6.1/x86_64-linux-gnu/

它们可以在 Project>Properties>C++ Include Paths 中设置

If this is an Eclipse issue rather than a compile issue then the problem is that there are a bunch of include directories that are missing from the indexers perspective.

Adding the following worked for me, but may depend on your particular setup where they actually exist:

/usr/include/c++/4.6.1
/usr/include/                
/usr/include/c++             
/usr/include/c++/4.6         
/usr/include/x86_64-linux-gnu
/usr/include/asm-generic
/usr/include/c++/4.6.1/x86_64-linux-gnu/

They can be set in Project>Properties>C++ Include Paths

阳光下的泡沫是彩色的 2024-12-14 08:53:51

如果您安装了 eclipse 的 CDT 插件,一切都应该开箱即用。
我尝试声明一个向量,但在实例化它时,它给出了相同的未解决的符号错误。检查 CDT 论坛,我发现有时将错误转变为警告是有效的。所以我只是忽略了编译错误并运行了该项目。它起作用了。

#include <vector>     // this was fine.  no complaints from eclipse

int main() {

std::vector V;        ///  vector was underlined red.  Just ignore and run.
V.push_back(1);

return 0;
}

If you installed the CDT plugin for eclipse, everything should work out of the box.
I tried to declare a vector but when it came to instantiating it, it gave the same unresolved symbol error. Checking CDT forums, i found that sometimes just turning errors to warnings worked. So i just ignored the compile errors and ran the project. It worked.

#include <vector>     // this was fine.  no complaints from eclipse

int main() {

std::vector V;        ///  vector was underlined red.  Just ignore and run.
V.push_back(1);

return 0;
}
瀟灑尐姊 2024-12-14 08:53:51
#include <map>
using namespace std;
map<string, SDL_Texture* > m_textureMap;

http://www.cplusplus.com/reference/map/map/map/

#include <map>
using namespace std;
map<string, SDL_Texture* > m_textureMap;

http://www.cplusplus.com/reference/map/map/map/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文