Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CAutoPtr::Attach

 

Call this method to take ownership of an existing pointer.


      void Attach(
   T* p 
) throw( );

p

The CAutoPtr object will take ownership of this pointer.

When a CAutoPtr object takes ownership of a pointer, it will automatically delete the pointer and any allocated data when it goes out of scope. If CAutoPtr::Detach is called, the programmer is again given responsibility for freeing any allocated resources.

In debug builds, an assertion failure will occur if the CAutoPtr::m_p data member currently points to an existing value; that is, it is not equal to NULL.

Example

See the example in the CAutoPtr Overview.

Requirements

Header: atlbase.h

Show: