
Hello,
I am trying to use the serialization library to save an object and a pointer to the object, but the pointer has the type of the object's base class.
// declaration MyClass myObject; // object, not pointer MyBaseClass *myPointer = &myObject;
// serialization code ar & BOOST_SERIALIZATION_NVP(myObject); ar & BOOST_SERIALIZATION_NVP(myPointer);
I have also noticed that saving a pointer of the object's type pointing to the object solves the problem: ... So is it a bug, or have I done something wrong ?
This seems to be a bug in the current serialization library. I've tracked it down to the fact that no basic_pointer_iserializer was registered before the pointer to the derived class gets deserialized. As far as I can tell a basic_pointer_iserializer only gets registered when an object is loaded through a pointer. That's also why it works when you additionally save a pointer to the object. I managed to fix it in my local copy and got your sample application to run with it successfully. The fix is straightforward. When basic_archive_impl::load_object is called it not only needs to register a basic_iserializer but also a basic_pointer_iserializer, just as basic_archive_impl::load_pointer does. So I simply changed it to also receive a basic_pointer_iserializer which is instantiated in the load_non_pointer_type structure in iserializer.hpp. However, I'm not sure if this is a good fix and so we'll have to wait what Robert has to say about this. Best Regards, Martin TAB Austria Industrie- und Unterhaltungselektronik GmbH & CoKG http://www.tab.at