0

I'm writing serialization for a third party library. I need to update this library with only replacing its files for the new ones, so I am unable to modify classes in those files. I need to deliver separate serialization files.

I must serialize protected members, should I make derived class, using it as a wrapper that can access protected members?

Alejandro Silvestri
  • 3,706
  • 31
  • 43
  • Derived class cannot access private members. If you have to serialize those, you'll have to modify the classes to get at their private members. You could add serialize methods, and possibly make deserialization ctors if they don't already have appropriate ones. I don't think it makes sense to used derived classes to implement seriaization. You'll end up having to move or copy the things you are serializing, which would be otherwise unnecessary and might complicate making an accurate serialization, depending on the situation. I would modify the source, or choose a lib with serialization support – Chris Beck Oct 01 '17 at 02:39
  • My mistake, I mean protected members, not private ones. I edited my question. Thank you for the comment. – Alejandro Silvestri Oct 01 '17 at 02:43
  • Don't miss the approach Tanner made in the comments at the linked duplicate. I've since created a full answer using that approach here: [Boost serialization of derived class with private members](https://stackoverflow.com/questions/45893929/boost-serialization-of-derived-class-with-private-members/45977995#45977995) – sehe Oct 01 '17 at 18:27

0 Answers0