如果我使用=運算符爲它指定一個新的指針,以前的指針是否會自動在std :: shared_ptr中被銷燬(或取消引用)?在std :: shared_ptr中使用=運算符時以前的指針是否被銷燬?
例如:
std::shared_ptr<Type> sp1 (ptr1, std::ptr_fun(destroy));
std::shared_ptr<Type> sp2 (ptr2);
sp1 = sp2; // now, will ptr1 be dereferenced and/or destroyed?
// and will the destroy() function get called?
當然,否則會泄漏。 – GManNickG 2012-07-30 03:44:19
你爲什麼不嘗試自己? – Zaffy 2012-07-30 03:52:22
Imo,如果一個智能指針實現沒有正確處理簡單的賦值...它不是一個非常聰明的指針。 – 2012-07-30 04:07:00