Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] Deserialization of base class fails
From: Robert Ramey (ramey_at_[hidden])
Date: 2014-10-25 12:47:53


Torsten Wylegala wrote
> But if I serialize the derived class "RequestPackage" and
> try to deserialize it into the base-class "Package" (Example 2) I'm
> getting an "input stream error" exception while trying to deserialize
> with ia >> BOOST_SERIALIZATION_NVP(*package);.

You can't do this. the class loaded must be the exact class saved.

> Background information: I want to use xml-serialized objects for data
> exchange via network and want all the packages to inherit from
> Package-class which carries "packageId" and therefore give me the chance
> to identify the incoming xml-objects and handle every package based on
> this id.

a very common scenario. Look more carefully in the documentation.
Look a tests - e.g. test_base_class.
Also there are examples.

--
View this message in context: http://boost.2283326.n4.nabble.com/Serialization-Deserialization-of-base-class-fails-tp4668492p4668494.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net