相关疑难解决方法(0)

初始化列表中的隐式转换失败

考虑一下片段:

#include <unordered_map>

void foo(const std::unordered_map<int,int> &) {}

int main()
{
        foo({});
}
Run Code Online (Sandbox Code Playgroud)

这与GCC 4.9.2失败并显示以下消息:

map2.cpp:7:19: error: converting to ‘const std::unordered_map<int, int>’ from initializer list would use explicit constructor ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const hasher&, const key_equal&, const allocator_type&) [with _Key = int; _Tp = int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, int> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type = long unsigned int; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher = std::hash<int>; std::unordered_map<_Key, …
Run Code Online (Sandbox Code Playgroud)

c++ gcc libstdc++ c++11

41
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

c++11 ×1

gcc ×1

libstdc++ ×1