Boost logo

Boost Users :

Subject: Re: [Boost-users] (De-) Serialization with constructor arguments
From: Kenny Riddile (kfriddile_at_[hidden])
Date: 2009-05-09 22:14:51


Damien Hocking wrote:
> Hi all,
>
> I'm using boost::serialization in a project and I was wondering if
> there's a way to deserialize through a non-default constructor that
> takes an argument. All the examples I've seen use default constructors.
>
> Damien

In many situations, constructing off of the input archive like this
works fine (assuming Foo is serializable):

Foo::Foo( InputArchive& archive )
{
     archive >> boost::serialization::make_nvp( "FooClass", *this );
}

This way, you could have additional constructor parameters besides the
archive if you needed to, and your class doesn't have to have a default
constructor.


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