1 | #include <boost/archive/binary_oarchive.hpp>
|
---|
2 | #include <boost/serialization/export.hpp>
|
---|
3 | #include <fstream>
|
---|
4 |
|
---|
5 | class base {
|
---|
6 | public:
|
---|
7 | virtual ~base() {}
|
---|
8 | private:
|
---|
9 | friend class boost::serialization::access;
|
---|
10 | template<class Archive>
|
---|
11 | void serialize(Archive &ar, const unsigned int version)
|
---|
12 | {
|
---|
13 | }
|
---|
14 | };
|
---|
15 |
|
---|
16 | class wrapper {
|
---|
17 | protected:
|
---|
18 | class derived : public base {
|
---|
19 | private:
|
---|
20 | friend class boost::serialization::access;
|
---|
21 | template<class Archive>
|
---|
22 | void serialize(Archive &ar, const unsigned int version)
|
---|
23 | {
|
---|
24 | boost::serialization::base_object<base>(*this);
|
---|
25 | }
|
---|
26 | };
|
---|
27 | public:
|
---|
28 | wrapper() : b(new derived()) {}
|
---|
29 | private:
|
---|
30 | base *b;
|
---|
31 | friend class boost::serialization::access;
|
---|
32 | template<class Archive>
|
---|
33 | void serialize(Archive &ar, const unsigned int version)
|
---|
34 | {
|
---|
35 | ar & b;
|
---|
36 | }
|
---|
37 | // uncommenting this line and the line below appear to work, so i'll write a macro for those.
|
---|
38 | //static ::boost::archive::detail::guid_initializer< wrapper::derived > const & guid_initializer;
|
---|
39 | };
|
---|
40 |
|
---|
41 | //::boost::archive::detail::guid_initializer< wrapper::derived > const & wrapper::guid_initializer = ::boost::serialization::singleton< ::boost::archive::detail::guid_initializer< wrapper::derived > >::get_mutable_instance().export_guid("derived");
|
---|
42 |
|
---|
43 | BOOST_CLASS_EXPORT_GUID(wrapper::derived, "wrapper::derived");
|
---|
44 |
|
---|
45 | main()
|
---|
46 | {
|
---|
47 | std::ofstream s("/tmp/foo.out");
|
---|
48 | boost::archive::binary_oarchive a(s);
|
---|
49 |
|
---|
50 | wrapper o = wrapper();
|
---|
51 |
|
---|
52 | a & o;
|
---|
53 | }
|
---|