Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-07-30 13:57:46

> class X { int x; };
> class Y { int y; };
> class Derived: public X, public Y {};
> The layout of Derived is going to be X::x followed by Y::y (or
> vice-versa). If you do:
> ptr<Derived> pd = new Derived (whatever syntax) ;
> ptr<Y> py = pd;
> ptr<X> px = pd;
> one of py, px is going to point into the middle of the Derived object;
> and then the imputed reference count location will be *wrong*. So
> either you need to forbid ptr's to multiply-derived objects or forbid
> conversions to base classes inside ptr's. Either of these is a pretty
> serious price to pay, IMHO.

Well it is easy to fix but haven't done it yet. You just implement some
sort of template constructor which will cast the offset properly with
static_cast<>s directly or assignments assertions.

Philippe A. Bouchard

Boost list run by bdawes at, gregod at, cpdaniel at, john at