---
name: "std::tr1::shared_ptr"
section: "3"
platform: "linux"
package: "libstdc++6-4.1-doc"
version: "4.1.2-25"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/std::tr1::shared_ptr"
---

# std::tr1::shared\_ptr(3)

## NAME

std::tr1::shared\_ptr -

## SYNOPSIS

## Detailed Description

### template\<typename \_Tp\> class std::tr1::shared\_ptr\< \_Tp \>

A smart pointer with reference-counted copy semantics. The object pointed to is deleted when the last **shared\_ptr** pointing to it is destroyed or reset.

Definition at line 485 of file boost\_shared\_ptr.h.

### Public Types

typedef \_Tp **element\_type**\

### Public Member Functions

\_Tp \* **get** () const \
 **operator \_\_unspecified\_bool\_type** () const \
 \_Reference **operator\*** () const \
 \_Tp \* **operator-\>** () const \
 template\<typename \_Tp1\> **shared\_ptr** & **operator=** (**std::auto\_ptr**\< \_Tp1 \> &\_\_r)\
 template\<typename \_Tp1\> **shared\_ptr** & **operator=** (const **shared\_ptr**\< \_Tp1 \> &\_\_r)\
 template\<typename \_Tp1, typename \_Deleter\> void **reset** (\_Tp1 \*\_\_p, \_Deleter \_\_d)\
 template\<typename \_Tp1\> void **reset** (\_Tp1 \*\_\_p)\
 void **reset** ()\
 template\<typename \_Tp1\> **shared\_ptr** (const **shared\_ptr**\< \_Tp1 \> &\_\_r, \_\_dynamic\_cast\_tag)\
 template\<typename \_Tp1\> **shared\_ptr** (const **shared\_ptr**\< \_Tp1 \> &\_\_r, \_\_const\_cast\_tag)\
 template\<typename \_Tp1\> **shared\_ptr** (const **shared\_ptr**\< \_Tp1 \> &\_\_r, \_\_static\_cast\_tag)\
 template\<typename \_Tp1\> **shared\_ptr** (**std::auto\_ptr**\< \_Tp1 \> &\_\_r)\
 template\<typename \_Tp1\> **shared\_ptr** (const weak\_ptr\< \_Tp1 \> &\_\_r)\
 template\<typename \_Tp1\> **shared\_ptr** (const **shared\_ptr**\< \_Tp1 \> &\_\_r)\
 template\<typename \_Tp1, typename \_Deleter\> **shared\_ptr** (\_Tp1 \*\_\_p, \_Deleter \_\_d)\
 template\<typename \_Tp1\> **shared\_ptr** (\_Tp1 \*\_\_p)\
 **shared\_ptr** ()\
 void **swap** (**shared\_ptr**\< \_Tp \> &\_\_other)\
 bool **unique** () const \
 long **use\_count** () const \

### Friends

template\<typename \_Del, typename \_Tp1\> \_Del \* **get\_deleter** (const **shared\_ptr**\< \_Tp1 \> &)\
 template\<typename \_Tp1\> bool **operator!=** (const **shared\_ptr** &\_\_a, const **shared\_ptr**\< \_Tp1 \> &\_\_b)\
 template\<typename \_Tp1\> bool **operator\<** (const **shared\_ptr** &\_\_a, const **shared\_ptr**\< \_Tp1 \> &\_\_b)\
 template\<typename \_Tp1\> bool **operator==** (const **shared\_ptr** &\_\_a, const **shared\_ptr**\< \_Tp1 \> &\_\_b)\
 class **shared\_ptr**\
 class **weak\_ptr**\

## Constructor & Destructor Documentation

### shared\_ptr ()` [inline]`

Construct an empty shared\_ptr.

**Postcondition:**

use\_count()==0 && get()==0

Definition at line 496 of file boost\_shared\_ptr.h.

### shared\_ptr (\_Tp1 \* \_\_p)` [inline, explicit]`

Construct a shared\_ptr that owns the pointer *p*.

**Parameters:**

*p* A pointer that is convertible to element\_type\*.

**Postcondition:**

use\_count() == 1 && get() == p

**Exceptions:**

**std::bad\_alloc***,in* **which case** `delete` *p* **is called.**

**Definition at line 506 of file boost\_shared\_ptr.h.**

### shared\_ptr (\_Tp1 \* \_\_p, \_Deleter \_\_d)` [inline]`

**Construct a shared\_ptr that owns the pointer** *p* **and the deleter** *d***.**

**Parameters:**

*p* **A pointer.** \
 *d* **A deleter.**

**Postcondition:**

**use\_count() == 1 && get() == p**

**Exceptions:**

**std::bad\_alloc***,in* **which case** *d(p)* **is called.**

**Definition at line 528 of file boost\_shared\_ptr.h.**

### shared\_ptr (const shared\_ptr\< \_Tp1 \> & \_\_r)` [inline]`

**If** *r* **is empty, constructs an empty shared\_ptr; otherwise construct a shared\_ptr that shares ownership with** *r***.**

**Parameters:**

*r* **A shared\_ptr.**

**Postcondition:**

**get() == r.get() && use\_count() == r.use\_count()**

**Exceptions:**

**std::bad\_alloc***,in* **which case**

**Definition at line 546 of file boost\_shared\_ptr.h.**

### shared\_ptr (const weak\_ptr\< \_Tp1 \> & \_\_r)` [inline, explicit]`

**Constructs a shared\_ptr that shares ownership with** *r* **and stores a copy of the pointer stored in** *r***.**

**Parameters:**

*r* **A weak\_ptr.**

**Postcondition:**

**use\_count() == r.use\_count()**

**Exceptions:**

*bad\_weak\_ptr* **when r.expired(), in which case the constructor has no effect.**

**Definition at line 560 of file boost\_shared\_ptr.h.**

### shared\_ptr (std::auto\_ptr\< \_Tp1 \> & \_\_r)` [inline, explicit]`

**Postcondition:**

**use\_count() == 1 and r.get() == 0**

**Definition at line 573 of file boost\_shared\_ptr.h.**

**References auto\_ptr::get().**

## Author

**Generated automatically by Doxygen for libstdc++ from the source code.**
