Boost logo

Boost :

From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-09-11 11:03:56


> -----Original Message-----
> From: Peter Dimov [mailto:pdimov_at_[hidden]]

> From: "Vladimir Prus" <ghost_at_[hidden]>

> > Peter Dimov wrote:
> > > Not only that, but you also need to register derived to base
> conversions,
> > > too, as I recently realized, since Derived * -> void * ->
> Base * is not
> > > required to work.
> >
> > Why do you need such a conversion?
>
> Because when you are reading a polymorphic object via a
> pointer to Base, you
> don't have Derived available at compile time; you only have a
> string that
> identifies that Derived. You can dispatch on that string and
> get back a
> void* to the object; now you must convert that void* to a Base*.

I assume you have some register function in the archive, and then a get_object(id) that performs new object with a different object depending on the id, and this is the void* returned. Couldn't you make this function templated, so that it knows it returns a Base? Then you could call get_object<Base>(id) and skip the void* step and this does not require you to inherit from any one specific class, making it possible to serialize hierarchies from libraries over which you have no control.

Also, couldn't you do this registration in some form of compile time making registration for each archive redundant? I think the serializations that I do are all capable of knowing this information in compile time (but I'm not sure).


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