Boost logo

Boost Users :

From: Alan M. Carroll (amc_at_[hidden])
Date: 2006-03-17 17:50:51


Define a copy contructor and assignment operator for the base class that does not copy/assign the reference count. Subclasses will use that for the members defined in the base class, i.e. it will solve the problem for all derived classes.

If you want it very clean, write a class that contains only the reference count with do-nothing copy/assignment and then use that as a base class for your current base class.

At 12:22 PM 3/17/2006, Thomas Laguzzi wrote:
>Hello,
>I use intrusive_ptr with a class that holds the refcount and I derive
>from that class all my other classes.
>
>class TObject {
> public :
>int refcount ;
>
>TObject () { refcount = 0;}
>
>
>}
>I have defined the intrusive_..._addref and _release to increase and
>decrease/delete that refcount and everything works good!
>
>Anywhay sometimes I need to assign a derived object to another derived
>object of the same type
>
>instrusive_ptr <Derived> A = new Derived;
>.
>.
>.
>the problem:
>*A = *Derived(constr parameters).
>The point is that the refcount is assigned too (and becames 0)
>
>How are instrusive_addref and _release supposed to be implemented ?
>
>Any quick and clean solution for that ? I cannot write assignment
>operator for every derived class because... there are a lot of members
>:)
>
>Really thanks!
>Thomas
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net