Boost logo

Boost Users :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2006-04-07 09:17:40


Robert Ramey wrote:
>> RIVASSEAU Jean Noel wrote:
>>> Ok, I will try to send a small example to the list tomorrow. In fact
>>> I think everything lies in the fact that using
>>> boost::serialization::base_object also registers the fact that the
>>> classes are parent and child. The serialization system needs to know
>>> that in order to make casts later.
>>>
>>> Somehow it probably does not like it when it tries to register
>>> several different classes as the parent of the same class.
>>>
>> Note that there is a test test_..._mi which tests serialization with
>> classes which have multiple parents. So I would hope that this
>> wouldn't be a problem. But you never know

Robert, the problem Jean is having is not related to multiple inheritance.
The problem above is best described:

class version 1:
================

struct base_old{ ... };

struct derived : base_old { ... };

class version 2:
================

struct base_new{ ... };

struct derived : base_new { ... };

What would the serialize or save/load function look like to support archives
containing version 1? I'd assume something along the lines of:

   template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        if( version == 2)
        {
            ar & boost::serialization::base_object<base_new>(*this);
        }
        else // while loading only
        {
            base_old lbase_old;

            ar & lbase_old;

            // update this base_new from deserialized base_old
        }
        ar & ...;
    }

I can imagine other complications if the program uses base_old pointers
anywhere as well.

Thanks, Jeff


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net