Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-13 10:18:59


Jeff Garland <jeff_at_[hidden]> writes:

> Loïc Joly wrote:
>> Jeff Garland a écrit :
>
>>> Oliver is correct -- serialization does not require default constructors for
>>> the types. It does require a constructed object prior to reading in the data.
>>
>> Yes, you are right. My mistake.
>>
>> What I meant is that for deserialisation, you still have a two phases
>> construction: First, build your object with any mean available (if your
>> object have only constructors with non-default parameters, this will
>> probably imply building them with dummy parameters), then, in a second
>> phase, override the member values by the serialized version.
>
> Yep.

Nope. Sorry to be blunt, but I just want to make absolutely sure this
isn't missed:

http://boost.org/libs/serialization/doc/serialization.html#constructors:

  template<class Archive>
  inline void load_construct_data(
      Archive & ar, my_class * t, const unsigned int file_version
  ){
      // retrieve data from archive required to construct new instance
      int m;
      ar >> m;
      // invoke inplace constructor to initialize instance of my_class
      ::new(t)my_class(m);
  }

One phase construction.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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