Boost logo

Boost Users :

Subject: [Boost-users] [Serialization] How to serialize a derived type but deserialize it as a base type pointer?
From: Jerry (jerryunsw_at_[hidden])
Date: 2011-04-10 23:51:34


I know that we can serialize/deserialize a derived type through a base type
pointer (using register_type()). But I cannot serialize a derived type and
deserialize it through a base type pointer. It seems to me the data type in
serialization and deserialization should be extactly the same one.

What I want is,

Base{...};
Derived : Base{...};

Derived d;
boost::archive::binary_oarchive oa(...);
oa << d; // serialize a derived object

Base *b;
boost::archive::binary_iarchive ia(...);
ia.register_type();
ia >> b // Deseiralize to a base type pointer

I have tried this but it does not work. Is there any way to make this work?

Many thanks!!!

--
View this message in context: http://boost.2283326.n4.nabble.com/Serialization-How-to-serialize-a-derived-type-but-deserialize-it-as-a-base-type-pointer-tp3440971p3440971.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