| Version: 3.0.5

- Main Page
- Related Pages
- Categories
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | List of all members
wxScopedPtr< T > Class Template Reference
Class List by Category » Smart Pointers

`#include <wx/scopedptr.h>`

## Detailed Description

### template<typename T>
class wxScopedPtr< T >

A scoped pointer template class.

It is the template version of the old-style scoped pointer macros.

Notice that objects of this class intentionally cannot be copied.

##

Library: wxBase
Category: Smart Pointers

See also
  wxSharedPtr<T>, wxWeakRef<T>

## Public Member Functions

| wxScopedPtr (T *ptr=NULL)
| Constructor takes ownership of the pointer. More...
| ~wxScopedPtr ()
| Destructor deletes the pointer. More...
T * | get () const
| Returns pointer to object or NULL. More...
| operator unspecified_bool_type () const
| Conversion to a boolean expression (in a variant which is not convertible to anything but a boolean expression). More...
T & | operator* () const
| Returns a reference to the object. More...
T * | operator-> () const
| Smart pointer member access. More...
T * | release ()
| Releases the current pointer and returns it. More...
void | reset (T *ptr=NULL)
| Reset pointer to the value of ptr. More...
void | swap (wxScopedPtr< T > &ot)
| Swaps pointers. More...

## Constructor & Destructor Documentation

template<typename T >

wxScopedPtr< T >::wxScopedPtr | ( | T * | ptr = `NULL` | ) |

Constructor takes ownership of the pointer.

Parameters

  ptr | Pointer allocated with `new` or NULL.

template<typename T >

wxScopedPtr< T >::~wxScopedPtr | ( |  | ) |

Destructor deletes the pointer.

## Member Function Documentation

template<typename T >

T* wxScopedPtr< T >::get | ( |  | ) | const

Returns pointer to object or NULL.

template<typename T >

wxScopedPtr< T >::operator unspecified_bool_type | ( |  | ) | const

Conversion to a boolean expression (in a variant which is not convertible to anything but a boolean expression).

If this class contains a valid pointer it will return true, if it contains a NULL pointer it will return false.

template<typename T >

T& wxScopedPtr< T >::operator* | ( |  | ) | const

Returns a reference to the object.

If the internal pointer is NULL this method will cause an assert in debug mode.

template<typename T >

T* wxScopedPtr< T >::operator-> | ( |  | ) | const

Smart pointer member access.

Returns pointer to object.

If the internal pointer is NULL this method will cause an assert in debug mode.

template<typename T >

T* wxScopedPtr< T >::release | ( |  | ) |

Releases the current pointer and returns it.

Remarks
  Afterwards the caller is responsible for deleting the data contained in the scoped pointer before.

template<typename T >

void wxScopedPtr< T >::reset | ( | T * | ptr = `NULL` | ) |

Reset pointer to the value of ptr.

The previous pointer will be deleted.

template<typename T >

void wxScopedPtr< T >::swap | ( | wxScopedPtr< T > & | ot | ) |

Swaps pointers.