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,

Derived : Base{...};

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

Base *b;
boost::archive::binary_iarchive ia(...);
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:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at