#include <iostream>
#include <fstream>
#include
#include #include //---------------------------------------------------------------------------- using namespace std;
//---------------------------------------------------------------------------- class A { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & a; ar & b; }
public: int a; int b;
};
//---------------------------------------------------------------------------- class B { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & ms; ar & a; } public:
public: B( const string& s ) : ms( s ){} void print(){ cout << ms << endl; } private: B(){} // use by serialization only string ms; A a; };
//---------------------------------------------------------------------------- int main() { // Save A* pa = new A;
Rather than put your program on my debugger, here is the way I anticipated that the library would be used: pa->a = 3; pa->b = 5; B* pb = new B( "this is test B" ); { std::ofstream ofs( "all.out" ); boost::archive::text_oarchive oa(ofs); oa << pa; ob << pb; delete pa; delete pb; } A* paa; B* pbb { std::ifstream ifs( "all.out", std::ios::binary ); boost::archive::text_oarchive ia(ifs); ia >> paa; ia >> pbb; } cout << "A: " << paa->a << " " << paa->b << endl; pbb->print(); delete paa; delete pbb; return 0; } Robert Ramey