|
Boost Users : |
Subject: Re: [Boost-users] Serialization / No Default Constructor / Messy
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-05-13 01:21:33
This subject is addressed in the documentation
Serialization->Reference->Serializable Concept->Pointers->Non-Default
Constructors
Robert Ramey
Dan Eaton wrote:
> Hi,
> My question is similar to past questions asked regarding what to do
> when a class to be deserialized does not have a default constructor.
> I'm wondering, though, if there is any better way to support both the
> BINARY and TEXT archive types, than doing this:
>
> class MyClass
> {
> public:
> MyClass(int myVar);
> MyClass( boost::archive::text_iarchive & ar )
> {
> ar >> *this;
> }
> MyClass( boost::archive::binary_iarchive & ar )
> {
> ar >> *this;
> }
>
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive & ar, const unsigned int /* fileVersion */ )
> {
> ar & myVar;
> }
>
> private:
> int myVar;
> }
>
> Specifically, I'd rather not have to have a constructor for each type
> of archive!
>
> Thanks :)
> Danny
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