Boost logo

Boost Users :

Subject: Re: [Boost-users] serialization: pointers to base classes
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-12-12 00:55:16


Hicham Mouline wrote:
> Hello,
> I am unclear about registration and export.
>
> I have this public single-derivation hierarchy
>
> B
>> \ \
> D1 D2 D3
>>
> D11
>
> The 5 structs are non abstract.

Then shouldn't need to register nor export anything.

> I will want to serialize (save) const B* and load it back with the
> serialization lib constructing for me (on the heap) the right object.

then it should polymorphic - i.e. have at least one virtual function.

> Did I understand right that the library does this for me?

yes

> Does it construct the object on the heap?

yes

> I export the 5 structs with the macro BOOST_CLASS_EXPORT_GUID(ns::B,
> "B") at global namespace level.

yes, but you would only need to apply this to the 4 derived classes

> Do I have to register them too?

no, it's either register or export. They are alternatives

> template <class Archive>
> void serialize(Archive &ar, ns::B&, const unsigned int version)
> {
> ar.template register_type<D1>();
> ar.template register_type<D2>();
> ar.template register_type<D3>();
> ar.template register_type<D11>();
> }

the above would be fine.

> or do I register for each class only the immediate derived?

you should need to do this (export or register) only for the
"leaf" classes.

Robert Ramey

>
> regards,


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