Initializing map of maps with initializer list in VS 2013(在 VS 2013 中使用初始化列表初始化地图映射)
问题描述
我正在尝试使用 C++11 初始化地图.我的编译器是 VS 2013 Express.
I'm trying to initialize map of maps using C++11. My compiler is VS 2013 Express.
unordered_map<EnumType, unordered_map<string, string>> substitutions = {
{
Record::BasementType,
{
{ "0", "" },
{ "1", "Slab or pier" },
{ "2", "Crawl" }
}
},
{
Record::BuildingStyle,
{
{ "0", "" },
{ "1", "Ranch" },
{ "2", "Raised ranch" }
}
},
// ... and so on
};
它已编译,但我在 ntdll.dll 中遇到断点.但是此代码的简化版本:
It's compile but I'm getting breakpoint inside ntdll.dll. However simplified version of this code:
unordered_map<EnumType, unordered_map<string, string>> substitutions = {
{
Record::BasementType,
{
{ "0", "" },
{ "1", "Slab or pier" },
{ "2", "Crawl" }
}
},
// *nothing more*
};
工作正常.
为什么当我在地图上有不止一对时这不起作用?如何做得更好?
Why this doesn't work when I have more than one pair in map? How to do it better?
推荐答案
这是一个已知的编译器错误,http://connect.microsoft.com/VisualStudio/feedback/details/800104/ .编译器会被初始化列表中的临时对象弄糊涂,甚至可以反复销毁单个对象.因为这是无声的糟糕代码生成,我已经要求编译器团队优先解决这个问题.
This is a known compiler bug, http://connect.microsoft.com/VisualStudio/feedback/details/800104/ . The compiler gets confused by temporaries in initializer lists, and can even destroy an individual object repeatedly. Because this is silent bad codegen, I've asked the compiler team to prioritize fixing this.
这篇关于在 VS 2013 中使用初始化列表初始化地图映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 VS 2013 中使用初始化列表初始化地图映射


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01