From: Robert Ramey (ramey_at_[hidden])
Date: 2004-05-07 10:49:13
> 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. Something like:
>MyClass myObject; // object, not pointer
>MyBaseClass *myPointer = &myObject;
>// serialization code
>ar & BOOST_SERIALIZATION_NVP(myObject);
>ar & BOOST_SERIALIZATION_NVP(myPointer);
>And I get an exception (either null reference exception or access
>violation) during the deserialization. I am using xml archives. The xml
>generated code seems fine.
I would expect and "unregistered_class" exception on both serialization and
de-serialization. If objects are to be serialized through a base class
pointer, they must either:
a) Be previously serialized directly or through the derived class pointer.
b) be "forward registered" with the archive.
c) be "exported" via BOOST_CLASS_EXPORT
>void serialize(Archive & ar, const unsigned int version)
> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
> // What is the intended purpose for the following?
> // I can't see why one would want to do this.
> /* uncomment to avoid the exception
> * ar & BOOST_SERIALIZATION_NVP(this);
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk