Boost serialization through base class
Hi, I've tried using the most basic example I can find in the documentation to serialize a class using a pointer to a polymorphic base. However, it only serializes the base class. I'm currently on 1.34.1. Am I missing something obvious? Sample code below: class base { public: friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int) { } }; class derived : public base { public: derived() : foo(5) { } friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int) { boost::serialization::base_object<base>(*this); ar & BOOST_SERIALIZATION_NVP(foo); } int foo; }; BOOST_CLASS_EXPORT_GUID(base, "base") BOOST_CLASS_EXPORT_GUID(derived, "derived") TEST(OMSTestSuite, BasicDeserializeTest) { std::ofstream ofs("test.out"); boost::archive::xml_oarchive toa(ofs); base *b = new derived; toa & BOOST_SERIALIZATION_NVP(b); }
Joe Drumm wrote:
Hi,
I've tried using the most basic example I can find in the documentation to serialize a class using a pointer to a polymorphic base. However, it only serializes the base class. I'm currently on 1.34.1.
Am I missing something obvious? Sample code below:
class base { public: friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int) { } virtual ~base(); // add this };
Make the base class polymorphic by adding the above. Did it not emit a compiler warning with a pointer to the the documentation? Robert Ramey
participants (2)
-
Joe Drumm
-
Robert Ramey