On 12/3/05 10:56 PM, "David Parks"
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.
Why don't you follow the error's advice and register the derived/base relationship? The registration is not automatic.
#include <string> #include <fstream>
#include
#include
#include #include #include
You already included the necessary header, but you don't exploit it.
#include
#include class A; class B;
class A { friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_className; }; std::string m_className; public: A() { m_className = "ClassA\n"; }; virtual void dumpFunc() {}; };
class B : public A { friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar, const unsigned int version) {
// Add this line to acknowledge base classes ar & boost::serialization::base_object<A>(*this);
ar & m_classNameB; }; std::string m_classNameB; public: B() { m_classNameB = "ClassB\n"; }; virtual void dumpFunc() {}; };
BOOST_CLASS_EXPORT(B)
void main() { std::vector vecA; B *b=new B(); vecA.push_back(b);
std::ofstream ofs("saveFile.sav"); boost::archive::text_oarchive oa(ofs); oa & vecA;
delete b; }
[TRUNCATE stack trace] -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com