#include #include #include #include class Father; class Child { public: Child(Father* f) : father(f) {} Child() {} Father* father = nullptr; template void serialize(Archive & ar, const unsigned int version); }; class Father { public: Child child; Father() : child(this) {} template void serialize(Archive & ar, const unsigned int version); }; template void Child::serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(father); } template void Father::serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(child); } int main() { { std::ofstream ofs("filename"); Father* father = new Father(); Child* child = &father->child; boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(child); // reversing the order of de/serialization prevents the crash oa << BOOST_SERIALIZATION_NVP(father); assert(child == &father->child); } { Father* father = nullptr; Child* child = nullptr; std::ifstream ifs("filename"); boost::archive::xml_iarchive ia(ifs); ia >> BOOST_SERIALIZATION_NVP(child); ia >> BOOST_SERIALIZATION_NVP(father); assert(child == &father->child); // fails } return 0; }