问题在最后两行代码中给出.
template<class T> // template class for smart
class SmartPtr { // pointers-to-T objects
public:
SmartPtr(T* realPtr = 0);
T* operator->() const;
T& operator*() const;
T* Detach( void )
{
T* pData = pointee;
pointee = NULL;
return pData;
}
private:
T *pointee;
...
};
class TestClass {}
SmartPtr<TestClass> sPtr(new TestClass);
TestClass* ptrA = sPtr->Detach();
// why I always see people use this method to access member functions of a Smart pointer.
// We can use sPtr-> b/c we have …Run Code Online (Sandbox Code Playgroud) c++ ×1