Serialization of a class hierarchy can be done as follows. The class hierarchy is:
- AB inherits from A
- ABC inherits from AB (which inherits from A), thus there cannot be at the same time ABC and DBC.
In the header file,
- Use one of the HPP_SERIALIZABLE macros.
- Except for the base class of the hierarchy (that is A), call
BOOST_CLASS_EXPORT_KEY(AB)
In the definition file,
- implement a function like
template<class Archive>
void AB::serialize(Archive & ar, const unsigned int version)
{
(void) version;
ar & make_nvp("base", base_object<A>(*this));
}
the called declaration macro.
Definition: serialization-fwd.hh:38
#define HPP_SERIALIZATION_IMPLEMENT(type)
Definition: serialization.hh:76
- Except for the base class of the hierarchy (that is A), call
BOOST_CLASS_EXPORT_IMPLEMENT(AB)
If you know a class will not have any serializable child (i.e. AB exists but there is no no ABC), then you can remove BOOST_CLASS_EXPORT_KEY(AB)
and replace BOOST_CLASS_EXPORT_IMPLEMENT(AB)
by BOOST_CLASS_EXPORT(AB)