
Jerry wrote:
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.
when you serialize through a derived type, extra information about the derived type isn't saved as it's assumed it will be deserialized the same way.
What I want is,
Base{...}; Derived : Base{...};
//Derived d;
Base *d = new Derived; // use this instead !!
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!!!