I'm modifying my code to include shared pointers instead of raw pointers. Is the following declaration valid?
for(//some loop//){
std::shared_ptr<foo> tmp;
/..do stuff to tmp../
vectorofpointer.push_back(tmp);
Additionally, once tmp goes out of scope, will this affect my vector?
Yes, it is ok.
See http://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr:
See also http://en.cppreference.com/w/cpp/memory/shared_ptr:
If your vector holds
shared_ptr
elements, your can still access the object pointed to aftertmp
has gone out of scope, since the reference count keeps the object alive.