Boost logo

Boost Users :

Subject: Re: [Boost-users] Serialize a class, call new() in constructor
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-10-05 12:35:29


Michael Reichlin wrote:
> Hi everybody,
>
> actually i have a big problem with serializing some of my classes. The
> problem is, that classA class calls new of classB in constructor and
> after that the load_construct_data is called and also calls a new of
> classB. So I have two objects of classB.
>
> serialize.h
> template<class Archive>
> void serialize(Archive &ar, CClassA &cCClassA, const unsigned int
> version)
> {

// Just comment out the following- don't serialize B
> ar & boost::serialization::make_nvp("ClassB", cCClassA.pClassB
> );

//

> }
>
> template<class Archive>
> void save_construct_data(Archive &ar, const CClassA *cCClassA,
> const unsigned int version)
> {
> ar << boost::serialization::make_nvp("Test",
> cCClassA->iTest);
> }
> template<class Archive>
> void load_construct_data(Archive &ar, CClassA *cCClassA, const
> unsigned int version)
> {
> int iTest;
> ar >> boost::serialization::make_nvp("Test", iTest);
> ::new(cCClassA) CClassA(iTest);
> }

> Now I just want that only one ClassB will be created. How can I
> recognize, that ClassB is already generate through cons
> tructor classA. I
> just want to serialize the members of classB.
>
> Is there a way to solve my problem??
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net