记录智能指针使用shared_ptr使用错误

shared_ptr为智能指针,今天一次在使用shared_ptr时,错误的将其初始化方式写为shared_ptr<T> test = shared_ptr<T>(),随后导致崩溃

正确做法是shared_ptr<T> test = make_shared<T>() 或shared_ptr<T> test = shared_ptr<T>(new T);切记  智能指针使用也不要忘记分配内存!!!

猜你喜欢

转载自www.cnblogs.com/wangshaowei/p/10583005.html