什么导致了 hash_map 错误,以及如何修复它?

huangapple go评论113阅读模式
英文:

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

问题

我正在尝试编译和运行这段GUI代码:

#include "Simple_window.h" // 获取窗口库的访问权限
#include "Graph.h" // 获取图形库的访问权限

int main()
{
    using namespace Graph_lib; // 我们的图形库位于Graph_lib命名空间
    Point tl{ 100, 100 }; // 作为窗口左上角的点
    Simple_window win{ tl, 600, 400, "Canvas" }; // 创建一个简单的窗口
    Polygon poly; // 创建一个形状(多边形)
    poly.add(Point{ 300, 200 }); // 添加一个点
    poly.add(Point{ 350, 100 }); // 添加另一个点
    poly.add(Point{ 400, 200 }); // 添加第三个点
    poly.set_color(Color::red); // 调整多边形的属性
    win.attach(poly); // 将多边形连接到窗口
    win.wait_for_button(); // 将控制权交给显示引擎
}

头文件和代码文件的来源:http://www.stroustrup.com/Programming/PPP2code/

我收到了hash_map错误:

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 Studio19\Professional\VC\Tools\MSVC.24.28314\include\hash_map    21

是什么导致了hash_map错误,我应该如何修复它?

英文:

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 Studio19\Professional\VC\Tools\MSVC.24.28314\include\hash_map    21

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

答案1

得分: 1

hash_map是早于C++11规范的旧API,其中他们决定将该容器命名为unordered_map。您需要改用该名称。

英文:

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.

答案2

得分: 1

这正是它所说的。

头文件 <hash_map> 不是标准的,但来自实际的STL。尽管它目前在您的平台上仍然可用,但它已经"被弃用并将被移除"。

您应该按照消息所说的切换到现代工具,如 std::unordered_map。不幸的是,这意味着偏离您的源材料。

我猜想错误本身来自于fltk(Bjarne的代码似乎没有包含该头文件,尽管我只是快速浏览了一下)。这些示例非常古老。

您可以从现代的书籍中学习C++。

与此同时,正如错误消息所说,您可以在项目设置的“预处理器定义”下定义 _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS,以便暂时承认这一点。

英文:

It's exactly what it says.

The header &lt;hash_map&gt; 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:

huangapple
  • 本文由 发表于 2020年1月4日 00:28:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582015.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定