只是想确定它实际上是一个错误而且我没有做错事。用gcc编译好(MinGW):
std::vector<size_t> a({1, 2}); // works
std::vector<size_t> b({1}); // does not work
std::vector<int> c({1}); // works
错误:
error C2440: 'initializing' : cannot convert from 'initializer-list' to 'std::vector<std::seed_seq::result_type,std::allocator<char32_t>>'
答案 0 :(得分:1)
这可能是VS2013中的一个错误,因为我相信在该版本中添加了初始化列表。请注意,如果省略()
,它似乎工作正常:
std::vector<size_t> b{ 1 }; // works
尝试其他一些变化也会产生一些令人惊讶的结果:
std::vector<size_t> b({ 1 }); // does not work
std::vector<size_t> b1({ 1u }); // does not work
std::vector<long> b2({ 1 }); // does not work
std::vector<long> b3({ 1l }); // works
std::vector<long long> b4({ 1l }); // does not work
std::vector<unsigned int> b5({ 1u }); // does not work
std::vector<size_t> b6{ 1 }; // works
std::vector<unsigned char> b7({ 1 }); // does not work
std::vector<unsigned char> b8({ 1u }); // works
std::vector<unsigned short> b9({ 1 }); // does not work
std::vector<unsigned short> b10({ 1u }); // works
std::vector<unsigned int> b11({ 1u }); // does not work
std::vector<int> b12({ 1u }); // works
std::vector<int> b13({ 1l }); // works
从上述所有未编译的案例中删除()
使其有效。