| 1 | #include <iostream>
|
|---|
| 2 | #include <fstream>
|
|---|
| 3 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 4 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 5 | #include <boost/serialization/export.hpp>
|
|---|
| 6 | #include <boost/serialization/base_object.hpp>
|
|---|
| 7 |
|
|---|
| 8 | using namespace boost;
|
|---|
| 9 | using namespace std;
|
|---|
| 10 |
|
|---|
| 11 | class Base1{
|
|---|
| 12 | friend class boost::serialization::access;
|
|---|
| 13 | public:
|
|---|
| 14 | Base1(){}
|
|---|
| 15 | virtual void print(){ cout << "Base1" << endl;}
|
|---|
| 16 | private:
|
|---|
| 17 | template<class Archive>
|
|---|
| 18 | void serialize(Archive & ar, const unsigned int version){}
|
|---|
| 19 | };
|
|---|
| 20 |
|
|---|
| 21 | BOOST_CLASS_EXPORT_GUID(Base1,"bugtry.Base1")
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | class Base2{
|
|---|
| 25 | friend class boost::serialization::access;
|
|---|
| 26 | public:
|
|---|
| 27 | Base2(){}
|
|---|
| 28 | virtual void print(){ cout << "Base2" << endl;}
|
|---|
| 29 | private:
|
|---|
| 30 | template<class Archive>
|
|---|
| 31 | void serialize(Archive & ar, const unsigned int version){
|
|---|
| 32 | }
|
|---|
| 33 | };
|
|---|
| 34 |
|
|---|
| 35 | BOOST_CLASS_EXPORT_GUID(Base2,"bugtry.Base2")
|
|---|
| 36 |
|
|---|
| 37 | class Derived:public Base1, protected Base2{
|
|---|
| 38 | friend class boost::serialization::access;
|
|---|
| 39 | public:
|
|---|
| 40 | Derived(){};
|
|---|
| 41 | virtual void print(){ cout << "Derived" << endl;}
|
|---|
| 42 | private:
|
|---|
| 43 | template<class Archive>
|
|---|
| 44 | void serialize(Archive & ar, const unsigned int version){
|
|---|
| 45 | ar & boost::serialization::base_object<Base1>(*this);
|
|---|
| 46 | ar & boost::serialization::base_object<Base2>(*this);
|
|---|
| 47 | }
|
|---|
| 48 | };
|
|---|
| 49 |
|
|---|
| 50 | BOOST_CLASS_EXPORT_GUID(Derived,"bugtry.Derived")
|
|---|
| 51 |
|
|---|
| 52 | int main(int argc,char **argv) {
|
|---|
| 53 | Derived d;
|
|---|
| 54 | d.print();
|
|---|
| 55 | ofstream o("bugtry.out");
|
|---|
| 56 | boost::archive::text_oarchive out(o);
|
|---|
| 57 | out << d;
|
|---|
| 58 | return 0;
|
|---|
| 59 | }
|
|---|