“符号‘地图’”无法解决”在命名空间中
你好!
我目前正在开发一个游戏引擎。尽管我才刚刚开始,但我已经遇到了问题。
我有这样的代码:
#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
可能是什么原因?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正确的限定名称是
::std::map
,因为您已经位于其他命名空间中。The correctly qualified name is
::std::map
, since you're already in some other namespace.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*>
要映射的第三个模板参数应该是比较函数。我猜你正在尝试从 int -> 映射(字符*,组件)。您需要将 char 和 Component* 包装成一个结构或一对......
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...
如果这是 Eclipse 问题而不是编译问题,那么问题在于从索引器的角度来看缺少一堆包含目录。
添加以下内容对我有用,但可能取决于它们实际存在的特定设置:
它们可以在
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:
They can be set in
Project>Properties>C++ Include Paths
如果您安装了 eclipse 的 CDT 插件,一切都应该开箱即用。
我尝试声明一个向量,但在实例化它时,它给出了相同的未解决的符号错误。检查 CDT 论坛,我发现有时将错误转变为警告是有效的。所以我只是忽略了编译错误并运行了该项目。它起作用了。
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.
http://www.cplusplus.com/reference/map/map/map/
http://www.cplusplus.com/reference/map/map/map/