简体   繁体   English

将MSVS 2010项目转换为MSVS 2012 RC但收到错误“C ++标准不提供此类型的哈希值”

[英]Converting MSVS 2010 project to MSVS 2012 RC but get error “The C++ standard doesn't provide a hash for this type”

I have a project working fine under MSVS 2010 SP1. 我有一个在MSVS 2010 SP1下工作正常的项目。 I'm trying to convert it to MSVS 2012 RC. 我正在尝试将其转换为MSVS 2012 RC。 I had to change some stuff, mainly related to C++ header/lib paths and MFC custom stuff. 我不得不改变一些东西,主要与C ++头/ lib路径和MFC自定义东西有关。 But I have one last hurdle to clear. 但我有最后一个障碍需要澄清。

In MSVC 2010, I'm using a lot of unordered_map<basic_string<TCHAR>, int> or map<basic_string<TCHAR>, int> . 在MSVC 2010中,我使用了很多unordered_map<basic_string<TCHAR>, int>map<basic_string<TCHAR>, int> It compiles fine. 它汇编得很好。 But in MSVS 2012, I just get this error: "The C++ standard doesn't provide a hash for this type" 但是在MSVS 2012中,我只是得到了这个错误:“C ++标准没有为这种类型提供哈希”

After searching a bit on the net, I found out that MSVS 2012 should be more close to the C++11 standard, and that the standard only defines hash functions for basic types and 4 defined string types (among them string and wstring , but basic_string not included). 在网上搜索了一下之后,我发现MSVS 2012应该更接近C ++ 11标准,并且标准只定义基本类型的哈希函数和4个定义的字符串类型(其中包括stringwstring ,但是basic_string不包括在内)。 So I changed all basic_string<TCHAR> to wstring but to no avail... I still get the same error. 所以我将所有basic_string<TCHAR>更改为wstring但无效...我仍然得到相同的错误。

What should I do to be able to compile my app again? 我该怎么办才能再次编译我的应用程序?

Apparently OOEngineer used basic_string without including the <string> header. 显然OOEngineer使用basic_string而不包括<string>头。 Part of the functionality might be visible anyway, through indirect includes by other headers. 无论如何,部分功能可能是可见的,通过其他标头的间接包含。

When VS2010 was released, the then proposed standard put all std::hash<> specializations in the <functional> header. 当VS2010发布时,当时提出的标准将所有std::hash<>放在<functional>头中。 In the final C++11 standard it was decided that it was better to put these together with the respective container, so some hash<> specializations were moved to <string> , <vector> , etc. 在最终的C ++ 11标准中,决定将它们与相应的容器放在一起更好,因此一些hash<>被移动到<string><vector>等。

So, to used all (or any , really) functionality of std::string , you have to include the <string> header yourself and not rely on another system header doing so. 因此,要使用std::string所有(或任何 ,真正的)功能,您必须自己包含<string>标头,而不是依赖于另一个系统标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM