Boost logo

Boost :

From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-06-30 09:59:14


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 27 June 2008 19:00 pm, Gennadiy Rozental wrote:
> 2. Why there is no something like this provided by the header:
>
> template<typename Derived>
> class intrusive_base {
> protected:
> intrusive_base() : m_counter( 0 ) {}
>
> private:
> friend void intrusive_ptr_add_ref( Derived* p ) { ++p->m_counter; }
> friend void intrusive_ptr_release( Derived* p ) { --p->m_counter; if(
> !p->m_counter ) delete p; }
>
> unsigned m_counter;
> };
>
> to be used like this:
>
> class Foo : intrusive_base<Foo>
> {
> ...
> };

One minor quibble: I think you left out a "public":

class Foo: public intrusive_base<Foo>

otherwise, I get compile errors unless I declare the add_ref/release functions
as friends to Foo also.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIaOa15vihyNWuA4URAvi9AKCZq/XrWxSV9pfC5GovTvwAPPtJBQCfTwef
vFFCEB61f0Sl6TLXjh8K1Os=
=AQdl
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk