Attempting to create a vector of shared_ptr to int.
Where am I going wrong? Thanks. Keith :^)
#include <iostream>
#include <vector>
#include <memory>
int main() {
std::vector<std::shared_ptr<int> > w;
std::vector<std::shared_ptr<int> >::iterator it_w;
w.push_back(new int(7));
std::cout << std::endl;
}
Compiler result:
pickledegg> g++ -std=c++11 -o shared_ptr shared_ptr.cpp
shared_ptr.cpp:29:4: error: no matching member function for call to 'push_back'
w.push_back(new int(7));
~~^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:697:36: note:
candidate function not viable: no known conversion from 'int *' to 'const value_type' (aka
'const std::__1::shared_ptr<int>') for 1st argument
_LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:699:36: note:
candidate function not viable: no known conversion from 'int *' to 'value_type' (aka
'std::__1::shared_ptr<int>') for 1st argument
_LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
^
1 error generated.