David Parks wrote:
> I'm having a newbie issue with serialization on a derived class with a
> virtual function.  I'm using the 1.33.0 build on VS 7.1.
> I've shrunken my code to a micro-version of what I tried to do.  Here
> I have two classes, A and B, where B is a subclass of A.  They share a
> virtual function (ie B overrides dumpFunc in A).  I've registered B
> with BOOST_CLASS_EXPORT(B).  I've turned on RTTI in VS 7.1 (/GR or
> whatever).  Still, I get a run time assert error in the boost library
> telling me that the derived/base relationship wasn't registered.
> Here's the code.  I'll try to spell out the error below.


> class B : public A
> {
>   friend class boost::serialization::access;
>
>   template<class Archive>
>       void serialize(Archive & ar, const unsigned int version)
>   {
>       ar & m_classNameB;
>   };
>   std::string m_classNameB;
> public:
>   B()
>   {
        ar & boost::serialization::base_object<A>(*this); //<<<<< inssert this !
>       m_classNameB = "ClassB\n";
>   };
>   virtual void dumpFunc() {};
> };
This little detail isn't that obvious - even though it is described in the manual.  Normally, derived
classes need to call serialization of their parents.  This fact is leveraged to "register"
the relationship between a derived class and its parent which is used
to serialization a derived class from a base class pointer.  If this "base_object"
isn't used, this relationship has to be made explicitly with "void_cast_register" from
and even more obscure lower level.
 
I made this change and verified that your program compiles and runs as
you would hope.
 
Robert Ramey