Boost logo

Boost Users :

From: Eric (eric-public_at_[hidden])
Date: 2005-05-28 14:56:46


Boost version: 1.32.0

I am trying to use the serialization class to serialize data pointed to by
the virtual base class. Note that the code works great if I don't use
virtual inheritance off of the base class. Here is a quick run-down of the
hierarchy and code:

class Base
{
virtual void OneOfManyVirtuals() = 0;
// Serialization Interface
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
//empty
}
};

BOOST_IS_ABSTRACT(Base);

class Derived : virtual public Base
{
virtual void OneOfManyVirtuals() { }
// Serialization Interface
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
//empty
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
}
}

// later in the main code
Base* pBase = new Derived;
boost::archive::xml_oarchive oa(ofs);

// doesn't work
oa << BOOST_SERIALIZATION_NVP(pBase);

// works
oa << BOOST_SERIALIZATION_NVP(*pBase);

When if fails, it fails in the oseralizer.hpp at line 419 with the comment:
// convert pointer to more derived type. if this is thrown
// it means that the base/derived relationship hasn't be registered

I tried registering the pairs with void_cast_register, but I wasn't
successful. Any real examples of how to use this method would be
appreciated.

So, does anyone know why the pointer to the base doesn't work when using
virtual inheritance? It works find when I remove the virtual from the
inheritance. Unfortunately, with the software architecture that I have,
there are several cases when the virtual inheritance off of interfaces is
required.

Any help with the matter is greatly appreciated.

-Eric


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