Lekan
Lekan

Reputation: 187

What causes a hash_map error and how can I fix it?

I am trying to compile and run this GUI code:

#include "Simple_window.h" // Get access to our window library
#include "Graph.h" // Get access to our graphics library facilities

int main()
{
    using namespace Graph_lib; // Our graphics facilities are in Graph_lib
    Point tl{ 100, 100 }; // To become top left corner of window
    Simple_window win{ tl, 600, 400, "Canvas" }; // Make a simple window
    Polygon poly; // Make a shape (a polygon)
    poly.add(Point{ 300, 200 }); // Add a point
    poly.add(Point{ 350, 100 }); // Add another point
    poly.add(Point{ 400, 200 }); // Add a third point
    poly.set_color(Color::red); // Adjust properties of poly
    win.attach(poly); // Connect poly to the window
    win.wait_for_button(); // Give control to the display engine
}

Source of headers and code files: http://www.stroustrup.com/Programming/PPP2code/

I get the hash_map error

Error (active)    E0035    #error directive: <hash_map> is deprecated and will be REMOVED. Please use <unordered_map>. You can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to acknowledge that you have received this warning.    ConsoleApplication1    C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.24.28314\include\hash_map    21

What causes an hash_map error and how can I fix it?

Upvotes: 0

Views: 632

Answers (2)

gct
gct

Reputation: 14583

hash_map is an old API predating the C++11 specification, where they decided the name for that container was unordered_map. You need to switch to using that name instead.

Upvotes: 1

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385325

It's exactly what it says.

The header <hash_map> is not standard, but came from the actual STL. Though it currently remains available on your platform, it's "deprecated and will be REMOVED".

You should do what the message says and switch to modern tools like std::unordered_map. Unfortunately that means straying from your source material.

I'm guessing the error itself comes from within fltk (none of Bjarne's code seems to include that header, though I only scanned through it quickly). These examples are very, very old.

You can learn C++ from a modern book, instead.

In the meantime, and again as the error message says, you can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS (in your project settings under "Preprocessor Definitions") to acknowledge this for now.


Similar question:

Upvotes: 1

Related Questions