Cro*_*ire 9 c++ vector std c++11
在现代C++中,我们可以初始化这样的向量:
std::vector<int> v = { 1, 2, 3, 4, 5 };
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试创建一个指向矢量的智能指针,这将无法编译:
auto v = std::make_shared<std::vector<int>>({ 1, 2, 3, 4, 5 });
Run Code Online (Sandbox Code Playgroud)
除了push_back在创作之后诉诸于s 之外还有其他更好的选择吗?
Sta*_*ght 12
auto v = std::make_shared<std::vector<int>>(std::initializer_list<int>{ 1, 2, 3, 4, 5 });
Run Code Online (Sandbox Code Playgroud)
这很有效.看起来编译器在没有直接指定initializer_list的情况下不能在make_unique params中吃{}.
次要编辑 - 使用MSVC 2015
| 归档时间: |
|
| 查看次数: |
2294 次 |
| 最近记录: |