C++ Hash Deprecation Warning

前端 未结 3 1028
梦如初夏
梦如初夏 2021-01-14 07:08

I am very new to C++ and programming in general and am currently working through Bjarne Stroustrup\'s Programming: Principles and Practices using C++. I\'m consistently rece

相关标签:
3条回答
  • You can put the define prior to your including of the header generating the warning:

    #define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
    #include <hash_map>
    

    You can also add the symbol in Proprocessor Definitions of the project file.

    enter image description here

    The later looks prettier, but given your doing something against the suggestion of the tool makers, I'd go with the first method, so you don't forget that you might get burnt latter.

    0 讨论(0)
  • 2021-01-14 07:38

    The warning isn't about "some function" - it's about the whole of stdext. And it's not just hand-wavy, to be discontinued eventually, deprecated: it doesn't ship with 2015.

    During the early 00's work was afoot to revise the C++ standard; different compiler vendors, Microsoft included, put proposals before the committee along with prototypes. So they could be tested and evaluated, Microsoft placed implementations of their proposed extensions in stdext.

    Eventually the committee chose what they were going to incorporate in that revision and released a Technical Report ("TR1"). Anticipating completion before the end of 2009, this was referred to as "C++0x", and compiler vendors began implementing these features in the tr1 namespace. Finally in 2011 the standard was finalized and we got "C++11" with all its bit and pieces back in std where they belong.

    According to Microsoft's proposal, the container would be std::hash_map, but the C++ committee chose to use the term unordered_map. std::map is an ordered container, stdext::hash_map, despite the name, is not.

    Microsoft's compiler has been the slowest at getting full C++11 support finished, and the standards committee has since finished a second variation (C++14) and is working on a third (C++17). Microsoft is just-about finishing C++11 in VS2015 and a big chunk of C++14, with a few significant exceptions that are apparently going to be a major problem for the VS compiler (esp constexpr and template variables).

    1. Visual Studio 2015 does not provide stdext - it's gone. This is not one of those "well, it may eventually go away" cases.

    2. stdext is specific to the Microsoft family of compilers, so writing code using stdext:: anything is not portable: http://ideone.com/x8GsKY

    3. The standardized version of the feature you're wanting is std::unordered_map, you should use that. It's essentially the same thing.

    4. There are unresolved bugs in stdext::hash_map.

    If you really have to use stdext::hash_map, silence the warning by adding

    #define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
    

    at the top of the stdafx.h I assume your project has, or in your header files before you #include <stdext/...>, or in the solution explorer:

    • Right click on your project's entry in solution explorer,
    • Select Properties,
    • Select Configuration: All Configurations,
    • Expand the C/C++ tree entry,
    • Select Preprocessor,
    • The "Preprocessor Definitions" will probably say <different options>
    • At the beginning of the "Preprocessor Definitions" entry add _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1; so it reads _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1;<different options>. (or whatever was there originally should follow the ;)
    0 讨论(0)
  • 2021-01-14 07:49

    It seems that you used old "std_lib_facilities.h" header (stroustrup.com/Programming/std_lib_facilities.h).

    New version of this header, working flawless for the "hello,world"-program in MSVS 2015, is available at stroustrup.com/Programming/PPP2code/std_lib_facilities.h

    Found it out when had had the same problem studying PPP.

    0 讨论(0)
提交回复
热议问题