Boost logo

Boost Users :

From: Will Lee (lee.will_at_[hidden])
Date: 2006-05-22 19:49:42

I've tried to searched for this in the archive and in google, but I can't
seem to find the answer.

I'm having trouble using boost::serialization with its non-intrusive. In
parituclar, I can't really figure out how to serialize derived classes that
do not have default constructors in an non-intrusive way.

class A;
class B : A;
class C : A;

Suppose B and C do not have a default constructor. And I would like to

A* b = new B(10);
A* c = new C("something");

Due to the restriction of the API that I can not change, all I have is the
pointer to A.

I'm puzzled on how this can be done. From reading the documentation and
source code, I think I need to override the load_construct_data and
save_construct_data, such as:

template<class Archive>
inline void load_construct_data(Archive &ar,
        A *t, const unsigned int vers) {

template<class Archive>
inline void save_construct_data(Archive &ar,
        A *t, const unsigned int vers) {


However, it seems like the memory is allocated already by the archiver with
the size of type A before calling the load_construct_data. How then can I
allcoate an object with type B or C?

There are examples on how this can be done intrusively, but since I don't
have control of the source, I really want to do it non-intrusively.

Any help is greatly appreciated.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at