#include #include #include #include #include #include struct B { int a; virtual ~B() {} }; struct D1 : public B { int b; }; namespace boost { namespace serialization { template void serialize(Archive& ar, B& g, const unsigned int version) { ar & g.a; } template void serialize(Archive& ar, D1& g, const unsigned int version) { ar & boost::serialization::base_object(g); ar & g.b; } } // namespace serialization } // namespace boost BOOST_CLASS_EXPORT_GUID(D1, "derived_one") int main() { D1 d; d.a = 5; d.b = 7; B* bptr = &d; std::ofstream ofs("1.out"); { boost::archive::text_oarchive oa(ofs); // write class instance to archive oa & bptr; // archive and stream closed when destructors are called } B* bb = 0; { // create and open an archive for input std::ifstream ifs("1.out"); boost::archive::text_iarchive ia(ifs); // read class state from archive ia & bb; // archive and stream closed when destructors are called } D1* dptr = dynamic_cast(bb); if (dptr==0) std::cerr<<" failed to load "<