c++boostboost-serialization

Is boost::serialization::base_object required every time I do inheritance?


I have:

  1. 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);
     }
    
  2. Should I expect some notes in documentation about this?


Solution

  • 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