
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