adl_serializer and objects sharing an abstract interface. #4401
-
I've been dabbling a lot with with serialization lately and I wanted more inputs on how to tackle it when you have have a few implementation classes inheriting from a common abstract interface. I've succeeded with the following setup, but as I'm not really proficient with templates yet, I'm sure there's a more elegant and/or efficient way of doing it.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
A couple notes that aren't specific to the library:
This is very defensive, but also verbose:
You can cut out a lot of duplicated code. Writing it more than once means that you have more than one chance to get it wrong, and more chance for it to get out of sync later:
Back to the original question, yes, in general, that's how you want to do polymorphic reading. However, you can separate the creation of the polymorphic object from the reading of the object data if they're default constructible.
|
Beta Was this translation helpful? Give feedback.
A couple notes that aren't specific to the library:
This is very defensive, but also verbose: