(De-) Serialization with constructor arguments
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
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.
You could also look at the documentation serialization->reference->Serializable Concept->Pointers->Non-Default constructors. Robert Ramey 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
That gets very close but not quite there. The problem is that the argument going through the constructor isn't serialized data so I can't read it from the archive. It comes from the main app. I could do some tap-dancing with copy constructors but that could get messy and slow and I'd rather not have a separate ::SetXYZ(ArgType arg) method that has to be called at the end of each serialization. That might be the simplest option though. Damien Robert Ramey wrote:
You could also look at the documentation
serialization->reference->Serializable Concept->Pointers->Non-Default constructors.
Robert Ramey
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
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Damien Hocking
-
Kenny Riddile
-
Robert Ramey