serialization: pointers to base classes
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. 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. Did I understand right that the library does this for me? Does it construct the object on the heap? I export the 5 structs with the macro BOOST_CLASS_EXPORT_GUID(ns::B, "B") at global namespace level. Do I have to register them too? 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>(); } or do I register for each class only the immediate derived? regards,
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,
participants (2)
-
Hicham Mouline
-
Robert Ramey