Class Ref<T>

#include <Geode/utils/cocos.hpp>
template<class T>classRef{ ... }

A smart pointer to a managed CCObject-deriving class. Retains shared ownership over the managed instance. Releases the object when the Ref is destroyed, or assigned another object or nullptr.

Use-cases include, for example, non-CCNode class members, or nodes that are not always in the scene tree.

Template parameters

T

A type that inherits from CCObject.
Examples2
class MyNode : public CCNode {
protected:
     // no need to manually call retain or
     // release on this array; Ref manages it
     // for you :3
     Ref<CCArray> m_list = CCArray::create();

     bool init() {
         if (!CCNode::init())
             return false;

         // No need to do m_list = CCArray::create()
         // or m_list->retain() :3

         return true;
     }
};
// Save a child from the current layer into a menu
Ref<CCMenu> menu = static_cast<CCMenu*>(this->getChildByID("main-menu"));
         
// Remove the menu from its parent
menu->removeFromParent();
         
// Menu will still point to a valid CCMenu as long as the menu variable exist
Public static methods0
Public member functions15
voidswap(
T*other
)

Swap the managed object with another object. The managed object will be released, and the new object retained

Parameters

other

The new object to swap to
T*data()const

Return the managed object

Return value
The managed object
T*operator*()const
No description provided
T*operator->()const
No description provided
T*operator=(
T*obj
)
No description provided
geode::Ref<T>&operator=(
geode::Ref<T>const&other
)
No description provided
geode::Ref<T>&operator=(
geode::Ref<T>&&other
)
No description provided
booloperator==(
T*other
)
const
No description provided
booloperator==(
geode::Ref<T>const&other
)
const
No description provided
booloperator!=(
T*other
)
const
No description provided
booloperator!=(
geode::Ref<T>const&other
)
const
No description provided
booloperator<(
geode::Ref<T>const&other
)
const
No description provided
booloperator<=(
geode::Ref<T>const&other
)
const
No description provided
booloperator>(
geode::Ref<T>const&other
)
const
No description provided
booloperator>=(
geode::Ref<T>const&other
)
const
No description provided
Fields0
Protected member functions0
Protected fields0