shared_ptr with vector
问题 I currently have vectors such as: vector<MyClass*> MyVector; and I access using MyVector[i]->MyClass_Function(); I would like to make use of shared_ptr . Does this mean all I have to do is change my vector to: typedef shared_ptr<MyClass*> safe_myclass vector<safe_myclass> and I can continue using the rest of my code as it was before? 回答1: vector<shared_ptr<MyClass>> MyVector; should be OK. But if the instances of MyClass are not shared outside the vector, and you use a modern C++11 compiler,