Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vector construction when wrapped in a Shared Pointer

So I am working on a transformation from an OO-language with garbage collection capabilities to C++. To start out I want to wrap all objects in shared pointers to solve the memory de-allocation issue. Right now I am trying to wrap a vector in a shared pointer and initializing the vector directly. See the issue below. Why is it not working and, if possible, how do I make it work?

vector<int> vec({ 6, 4, 9 }); // Working

shared_ptr<vector<int>> vec = make_shared<vector<int>>({ 6, 4, 9 }); // Not working

Sorry for not including the error, the error I am getting is marked at (make_shared) and printed as:

no instance of function template "std::make_shared" matches the argument list
argument types are: ({...})

Thanks for any answers!

like image 299
Flipbed Avatar asked Mar 05 '15 12:03

Flipbed


Video Answer


1 Answers

auto vec = make_shared<vector<int>>(std::initializer_list<int>{ 6, 4, 9 });
like image 149
nh_ Avatar answered Oct 22 '22 12:10

nh_