$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Hugh Hoover (hugh_at_[hidden])
Date: 2006-05-20 15:50:50
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.