Skip to content

Instantly share code, notes, and snippets.

@chadaustin
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadaustin/62db729bc13952fc47a6 to your computer and use it in GitHub Desktop.
Save chadaustin/62db729bc13952fc47a6 to your computer and use it in GitHub Desktop.
#include <boost/serialization/base_object.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/export.hpp>
struct base {
virtual ~base() {}
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
}
};
struct derived : base {
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<base>(*this);
}
};
BOOST_CLASS_EXPORT_GUID(derived, "derived")
int main() {
base* b = new derived;
boost::archive::text_oarchive oa(std::cout);
oa & b;
}
// prints
// 22 serialization::archive 10 1 7 derived 1 0
// 0 1 0
// 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment