| 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 Derived:protected Base1{
 | 
|---|
| 25 |   friend class boost::serialization::access;
 | 
|---|
| 26 | public:
 | 
|---|
| 27 |   Derived(){};
 | 
|---|
| 28 |   virtual void print(){ cout << "Derived" << endl;}
 | 
|---|
| 29 | private:
 | 
|---|
| 30 |   template<class Archive>
 | 
|---|
| 31 |   void serialize(Archive & ar, const unsigned int version){
 | 
|---|
| 32 |     ar & boost::serialization::base_object<Base1>(*this);
 | 
|---|
| 33 |   }
 | 
|---|
| 34 | };
 | 
|---|
| 35 | 
 | 
|---|
| 36 | BOOST_CLASS_EXPORT_GUID(Derived,"bugtry.Derived")
 | 
|---|
| 37 | 
 | 
|---|
| 38 | int main(int argc,char **argv) {
 | 
|---|
| 39 |   Derived d;
 | 
|---|
| 40 |   d.print();
 | 
|---|
| 41 |   ofstream o("bugtry.out");
 | 
|---|
| 42 |   boost::archive::text_oarchive out(o);
 | 
|---|
| 43 |   out << d;
 | 
|---|
| 44 |   return 0;
 | 
|---|
| 45 | }
 | 
|---|