Boost logo

Boost :

From: Jon Kalb (jonkalb_at_[hidden])
Date: 2003-02-12 01:57:28


On 2003-02-11 8:47 PM, "Philippe A. Bouchard" <philippeb_at_[hidden]>
wrote:

> Jon Kalb wrote:
>
> [...]
>
>> If a user attempts to use this on a non-polymorphic object, will they
>> get a compile time error or run-time error?
>
> No compile-time error, but a run-time error may occur if multiple
> inheritance is used. There is basically nothing we can do in this
> situation:
>
> class A { char c; };
>
> class B { char c; };
>
> class C : public A, public B { char c; };
>
>
> C * pC = new C; // Let's say pC == 0x8000
>
> B * pB = pC; // pB == 0x8001
>
> pick_of(pB) will return 0x8001. It is similar to a "delete pB" attempt.

This is as I suspected.

I wonder if it wouldn't be better to have a compile time error in this
situation rather than to create a trap for the unsuspecting. It does put an
additional burden on the user to ensure that the types are indeed
polymorphic, but I think they have that burden in any case. The currently
implementation allows them to be blissfully ignorant of this situation.

I appreciate that your library will document that it only works for
polymorphic types, but I fear that to be an insufficient prophylactic.


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