Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-05-07 10:49:13

Francois wrote:

> 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:

>// declaration
>MyClass myObject; // object, not pointer
>MyBaseClass *myPointer = &myObject;

>// serialization code

>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

>template<class Archive>
>void serialize(Archive & ar, const unsigned int version)
> {
> // What is the intended purpose for the following?
> // I can't see why one would want to do this.
> /* uncomment to avoid the exception
> */
> }

Robert Ramey

Boost list run by bdawes at, gregod at, cpdaniel at, john at