toast::enable_unintrusive_from_this< T > Class Template Reference
[toast unintrusive pointer]

#include <toast/enable_unintrusive_from_this.hpp>

List of all members.


Detailed Description

template<class T>
class toast::enable_unintrusive_from_this< T >

Allows you to return an unintrusive_ptr to *this.

Sometimes it is desirable to be able to return a smart pointer that points to 'this.' Even if you could construct an unintrusive_ptr from a raw pointer, you wouldn't want to do this because it would receive a new reference count and a double free would eventually occur. This solution to the problem is taken from boost::shared_ptr. You have your class subclass this one, which will add an internal weak pointer to your class. Then your class' member functions can call unintrusive_from_this() to get a legitimate unintrusive_ptr.

Warning:
If you are using this you should probably inherit from it at the top of your class's inheritance hierarchy. If you introduce it in the middle you have created a multiply-derived class, and unintrusive_ptr has special rules with multiply-derived classes when dealing with base class pointers to derived class objects. See unintrusive_ptr's documentation for details.

Protected Member Functions

 enable_unintrusive_from_this (enable_unintrusive_from_this const &)
enable_unintrusive_from_thisoperator= (enable_unintrusive_from_this const &)
unintrusive_ptr< T > unintrusive_from_this ()
unintrusive_ptr< T const > unintrusive_from_this () const

Friends

class unintrusive_ptr

The documentation for this class was generated from the following file:

SourceForge.net Logo