I have:
non-polymorphic (no virtual methods) class hierarchy;
base class already contains serialize
;
child classes are serialized directly;
class A
{
private:
int x;
int y;
template<typename Archive>
void serialize(Archive& ar, const unsigned int)
{
ar & x & y;
}
};
class B : public A { /* no data members*/ };
class C : public A { /* no data members*/ };
Do I need serialize
function in classes B
and C
?
serialize
function in B
and C
is exactly this:
template<typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object<A>(*this);
}
Should I expect some notes in documentation about this?
No. If you don't want to serialize data from the base, you may not need it.
However, in polymorphic hierarchies you do need it if only to tell the archive about the registered types.
See https://www.boost.org/doc/libs/1_73_0/libs/serialization/doc/serialization.html
See here for lots of examples: https://stackoverflow.com/a/35756430/85371