相关疑难解决方法(0)

为什么auto x {3}推导出initializer_list?

我喜欢autoC++ 11.太棒了.但它有一个不一致,真的让我紧张,因为我一直绊倒它:

int i = 3;       // i is an int with value 3
int i = int{3};  // i is an int with value 3
int i(3);        // i is an int with value 3 (possibly narrowing, not in this case)
int i{3};        // i is an int with value 3

auto i = 3;      // i is an int with value 3
auto i = int{3}; // i is an int with value 3
auto i(3); …
Run Code Online (Sandbox Code Playgroud)

c++ initializer-list auto c++11 type-deduction

56
推荐指数
1
解决办法
4532
查看次数

标签 统计

auto ×1

c++ ×1

c++11 ×1

initializer-list ×1

type-deduction ×1