# ndk::SharedRefBase


`#include <binder_interface_utils.h>`

Binder analog to using std::shared_ptr for an internally held refcount.

## Summary

ref must be called at least one time during the lifetime of this object. The recommended way to construct this object is with [SharedRefBase::make](https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base_1a68ccdf210a9f41b80b198991aecab6aa).

If you need a "this" shared reference analogous to shared_from_this, use this-\>[ref()](https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base_1a8b23f8ea6eef399879ee4cd8e1e6ec42).

### Inheritance

Direct Known Subclasses:[ndk::ICInterface](https://developer.android.com/ndk/reference/classndk/1-1-i-c-interface)

| ### Constructors and Destructors ||
|---|---|
| `https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base_1a128cf3f78a66110828c9c1411f89ff64()` ||
| `https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base_1af3614d28ef88d2a83eaac00ed051c3fa()` ||

| ### Public functions ||
|---|---|
| `https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base_1a8b23f8ea6eef399879ee4cd8e1e6ec42()` | `std::shared_ptr< https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base >` A shared_ptr must be held to this object when this is called. |
| `https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base_1a1ac6bac0ba652e50e8843cedbcb6dc5e()` | `std::shared_ptr< CHILD >` Convenience method for a ref (see above) which automatically casts to the desired child type. |

| ### Public static functions ||
|---|---|
| `https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base_1a68ccdf210a9f41b80b198991aecab6aa(Args &&... args)` | `std::shared_ptr< T >` Convenience method for making an object directly with a reference. |
| `https://developer.android.com/ndk/reference/classndk/1-1-shared-ref-base#classndk_1_1_shared_ref_base_1a687b650d4ed7900e444894ab8f934265(void *p)` | `void` |

## Public functions

### SharedRefBase

```
 SharedRefBase()
```

### ref

```
std::shared_ptr< SharedRefBase > ref()
```
A shared_ptr must be held to this object when this is called.

This must be called once during the lifetime of this object.

### ref

```
std::shared_ptr< CHILD > ref()
```
Convenience method for a ref (see above) which automatically casts to the desired child type.

### \~SharedRefBase

```
virtual  ~SharedRefBase()
```

## Public static functions

### make

```
std::shared_ptr< T > make(
  Args &&... args
)
```
Convenience method for making an object directly with a reference.

### operator delete

```
void operator delete(
  void *p
)
```