Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-05-20 17:49:11


Hugh Hoover wrote:
> On May 19, 2006, at 09:16, Catalin Pitis wrote:
>> I wonder how can a class that doesn't provide a default constructor
>> can be serialized? As far as I saw, the serialization methods assume
>> that the object is already created. This makes me nervous :), because
>> I wouldn't create an object that is not in a valid state after
>> creation...
>>
>> Am I missing something in this library? Can I do it "the easy way"?
>
> save_construct_data and load_construct data are the correct methods
> here - although I'm not sure how to use load_construct_data with a
> class derived from an abstract class.
>
> I've gone round on this myself in the last couple of days and decided
> that unless the object absolutely CANNOT be constructed with a
> default constructor (e.g., the class holds a reference), it's better
> to have a private default constructor and a serialize method than to
> try and use (save|load)_construct_data - mostly for the item cited
> above about load_construct_data with a derived class.
>
> Robert Ramey has mentioned in other messages that default
> construction with de-serializing is tantamount to "proper"
> construction anyway, and I agree with that - you need to consider the
> de-serialization as a form of construction rather than something you
> do the object after construction.

Hmmm - I don't remember saying that. In any case I feel quite
confident that the load_constract_data method is functional,
convenient, and even necessary in some cases. I have in
reason to believe that it doesn't work with abstract base
classes either. The serialization library keeps track of the
types of derived pointers.

Robert Ramey


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