More Effective C++ smart pointer 问题
template<class T> //
class SmartPtr { //
public:
SmartPtr(T* realPtr = 0);
T* operator->() const;
T& operator*() const;
template<class newType> //
operator SmartPtr<newType>() // 这里返回的是一个新的SmartPtr 的临时对象。临时对象解构的时候岂不是把 pointee 也删除了?
{
return SmartPtr<newType>(pointee);
}
...
};
SmartPtr<Cassette> funMusic(new Cassette("Alapalooza"));
SmartPtr<CD> nightmareMusic(new CD("Disco Hits of the 70s"));
void displayAndPlay(const SmartPtr<MusicProduct>& pmp,
int howMany);
在经过上面的调用的时候,funMusic 的解构是否将删除已经被删除的对象了?