c++ - C2338 : The C++ Standard doesn't provide a hash for this type with string and unique_ptr

标签 c++ visual-c++ c++11 hash unordered-map

我正在尝试实现一个 std::unordered_map,其中 std::string 作为键,std::unique_ptr 作为值。但是,当我尝试编译时,出现错误:

错误 C2338:C++ 标准不提供此类型的散列。

环顾四周,我知道 C++11 确实包含一个 std::hash < std::string >,我看不出为什么会抛出这个错误。我已经尝试实现我自己的散列函数,就像看到的那个 here , 但它仍然抛出相同的错误。我也尝试过使用 __declspec(dllexport) 并将包含类的复制构造函数和赋值运算符设为私有(private),正如某些线程中建议的那样使 unique_ptr 工作,但无济于事。

这是违规类的代码:

#ifndef __TEXTURE_MAP_H__
#define __TEXTURE_MAP_H__

#include <unordered_map>
#include <vector>
#include <memory>
#include <string>

//__declspec for std::unique_ptr compat.
class /*__declspec(dllexport)*/ TextureMap : virtual public IconRegister
{
private:
    uint32 _textureId;
    std::unordered_map<const std::string, std::unique_ptr<AtlasTexture> > _registeredIcons;
    std::unordered_map<const char*, AtlasTexture*> _uploadedIcons;
    std::vector<AtlasTexture*> _animatedIcons;

public:
    TextureMap();
    ~TextureMap();

    uint32 getTextureId();

    void loadTextureAtlas();

    /* override */ IIcon& registerIcon(const char*);
    void registerIcons();

private:
    TextureMap(const TextureMap& other) { }
    TextureMap& operator= (const TextureMap& other) { return *this; };
};

#endif

我找不到任何原因这不应该工作,并且我已经尝试了几乎所有我在搜索问题时可以找到的其他解决方案。

我正在使用 MSVC 2012。

非常感谢任何帮助。谢谢。

编辑:添加 AtlasTexture 类:headerimplementation

编辑:我对移动和移动分配的实现:here .

最佳答案

您是否尝试过在 AtlasTexture 中实现所有编译生成的方法?

关于c++ - C2338 : The C++ Standard doesn't provide a hash for this type with string and unique_ptr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21747156/

相关文章:

c++ - 在 Windows 2008 R2 SP1 上使用 GetVersionEx 时出现错误行为

c++ - 来自 iso C++ n3290 : Argument dependant Name Lookup: 的一个点

c++ - 在 VC++ 2008 中嵌入/加载 DLL 作为资源?

c++ - C 和 C++ 中 void 指针的区别

c++ - 人口数据的生成方式

c++ - 为什么编译器左移0?

生成轻量级可执行文件的 C 编译器

c++ - 标准库中是否有匹配 std::thread 的构造函数语义的类型删除函数包装器?

c++ - CRT 检测到应用程序在堆缓冲区(新建/删除)类结束后写入内存

c++ - 创建对象数组 - 从类模板继承并使用 C++ 中的构造函数