glibmm 2.80.0
|
A reference-counting shared smartpointer. More...
Typedefs | |
template<class T_CppObject > | |
using | Glib::RefPtr = std::shared_ptr< T_CppObject > |
RefPtr<> is a reference-counting shared smartpointer. | |
A reference-counting shared smartpointer.
using Glib::RefPtr = typedef std::shared_ptr<T_CppObject> |
RefPtr<> is a reference-counting shared smartpointer.
Some objects in gtkmm are obtained from a shared store. Consequently you cannot instantiate them yourself. Instead they return a RefPtr which behaves much like an ordinary pointer in that members can be reached with the usual object_ptr->member
notation.
Reference counting means that a shared reference count is incremented each time a RefPtr is copied, and decremented each time a RefPtr is destroyed, for instance when it leaves its scope. When the reference count reaches zero, the contained object is deleted, meaning you don't need to remember to delete the object.
RefPtr is a std::shared_ptr with a special deleter. To cast a RefPtr<SomeType> to a RefPtr<SomeOtherType>, use one of the standard library functions that apply a cast to the stored pointer, for instance std::dynamic_pointer_cast.
Example:
See the "Memory Management" section in the "Programming with gtkmm" book for further information.