Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-11-19 12:53:51


Robert Ramey wrote:

>>Now, am I right in assuming that you can detect the case where most
>>derived type is not equal to static type only for polymorphic classes?
>
> RTTI only detects differences for polymorphic classes (those with at least
> one virtual function). If one wants to do this on other classes he will
> have
> to use a custom extended_type_info. An example of this is in the tests.

Ah.. so if I want to serialize objects to derived class via pointer to base
class, I've two choices:
1. Make the base class polymorphic (good idea anyway)
2. Write custom extended_type_info.

>> Is so, then you can use
>
>> dynamic_cast<void*>(ptr);
>
> You can? That would surprise me ! I don't find such a thing in any of my
> references.

At least the standard say so explicitly. If 'ptr' is a pointer to
polymorphic class, dynamic_cast to void*, possible cv-qualified, gives you
a pointer to most derived object.

> void_cast basically (re?)implements this functionality. The
> difference would be that void_cast doesn't necessarily depend upon RTTI.

Hmm.. if so, then it's a question if this complexity is needed. BTW, I'm not
sure about casting in the opposite direction -- when it's needed and if it
can be replaced with some portable code. Gotta look at it.

- Volodya


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