gpt4 book ai didi

c++ - 一对 map 的静态初始化

转载 作者:太空狗 更新时间:2023-10-29 19:43:23 25 4
gpt4 key购买 nike

我正在尝试静态初始化包含一对的映射:

typedef map<int, pair<int, int>> mytype;
static const mytype mymap = { 3, {3, 0} };

我正在使用 Visual Studio 2013,但出现错误:

 error C2440: 'initializing' : cannot convert from 'initializer-list' to 'std::map<int,std::pair<int,int>,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>'

知道是什么原因造成的吗?我认为 VS2013 具有此 C++11 功能。

最佳答案

您缺少一副牙套:

static const mytype mymap = { { 3, {3, 0} } };
^ ^ ^
| | pair<int,int> (value)
| pair<const key, value> (map element)
map<key, value>

关于c++ - 一对 map 的静态初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28929113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com