TSharedRef

NOTE: [TSharedRef](API\Runtime\Core\Templates\TSharedRef) is an Unreal extension to standard smart pointer feature set.

Windows
MacOS
Linux

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Templates/SharedPointer.h

Include

#include "Templates/SharedPointer.h"

Syntax

template<class ObjectType, ESPMode Mode>
class TSharedRef

Remarks

TSharedRef is a non-nullable, non-intrusive reference-counted authoritative object reference.

This shared reference will be conditionally thread-safe when the optional Mode template argument is set to ThreadSafe.

Forward declarations. Note that in the interest of fast performance, thread safety features are mostly turned off (Mode = ESPMode::Fast). If you need to access your object on multiple threads, you should use ESPMode::ThreadSafe!

Constructors

Name Description

Public function

TSharedRef()

Constructs default shared reference that owns the default object for specified type.

Public function

TSharedRef

(
    TSharedRef< OtherType, Mode > const...,
    SharedPointerInternals::FStaticCast...
)

Special constructor used internally to statically cast one shared reference type to another.

Public function

TSharedRef

(
    TSharedRef< OtherType, Mode > const...,
    SharedPointerInternals::FConstCastT...
)

Special constructor used internally to cast a 'const' shared reference a 'mutable' reference.

Public function

TSharedRef

(
    TSharedRef< OtherType, Mode > const...,
    ObjectType* InObject
)

Aliasing constructor used to create a shared reference which shares its reference count with another shared object, but pointing to a different object, typically a subobject.

Public function

TSharedRef

(
    OtherType* InObject
)

NOTE: TSharedRef has no default constructor as it does not support empty references.

Public function

TSharedRef

NOTE: The following is an Unreal extension to standard shared_ptr behavior.

Public function

TSharedRef

(
    TSharedRef< OtherType, Mode > const...
)

Constructs a shared reference as a reference to an existing shared reference's object.

Public function

TSharedRef

(
    TSharedRef const& InSharedRef
)

Public function

TSharedRef

(
    TSharedRef&& InSharedRef
)

Public function

TSharedRef

(
    OtherType* InObject,
    DeleterType&& InDeleter
)

Constructs a shared reference that owns the specified object. Must not be nullptr.

Functions

Name Description

Public function Const

ObjectType &

 

Get()

Returns a C++ reference to the object this shared reference is referencing

Public function Const

const int32

 

GetSharedReferenceCount()

Returns the number of shared references to this object (including this reference.) IMPORTANT: Not necessarily fast! Should only be used for debugging purposes!

Public function Const

const bool

 

IsUnique()

Returns true if this is the only shared reference to this object.

Operators

Name Description

Public function Const

ObjectType &

 

operator*()

Dereference operator returns a reference to the object this shared pointer points to

Public function

TSharedRef &

 

operator=

(
    TSharedRef const& InSharedRef
)

Assignment operator replaces this shared reference with the specified shared reference.

Public function

TSharedRef &

 

operator=

(
    TSharedRef&& InSharedRef
)

Public function

TSharedRef &

 

operator=

NOTE: The following is an Unreal extension to standard shared_ptr behavior.

Public function Const

ObjectType &...

 

operator->()

Arrow operator returns a pointer to this shared reference's object

Typedefs

Name

Description

ElementType

Select Skin
Light
Dark

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback