Creating a shared_ptr of vector in C++ [duplicate]

独自空忆成欢 提交于 2019-12-05 03:29:06
auto v = std::make_shared<std::vector<int>>(std::initializer_list<int>{ 1, 2, 3, 4, 5 });

This is working. Looks like compiler cannot eat {} in make_unique params without direct specification of initializer_list.

Minor edit - used MSVC 2015

You can alternatively do it by creating another vector directly in parameter in order to move it:

auto v = std::make_shared<std::vector<int>>(std::vector<int>({ 1, 2, 3, 4, 5 }));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!