[serialization] Lost in serialization (save_construct_data and reference)
Hello, Four questions about serialization :=) Let's go. 1) I have a class that have a reference on a vector of shared pointers to objects . Since I have no default constructors I redefined save_construct_data like this : template<class Archive> inline void save_construct_data( Archive & ar, const MyClass<Real> * t, // CLASS IS TEMPLATED const unsigned int file_version) { ar << & t->myref_; } I have got the following error (same problem with & operator): error: no match for 'operator<<' in 'ar << [...] 2) I there a tricky way to define this function for all type used to instantiate MyClass ? 3) Is it me or this example in the documentation : // save data required to construct instance ar << t.member1; // serialize reference to object as a pointer ar << & t.member2; should be : ar << t->member1; ar << & t->member2; ? 4) Should it be possible to add more examples which use templates in the library (since a lot of a macros are not available) ? Thanks in advance for your help!
codeur@altern.org wrote:
Hello,
Four questions about serialization :=) Let's go.
1)
I have a class that have a reference on a vector of shared pointers to objects . Since I have no default constructors I redefined save_construct_data like this :
template<class Archive> inline void save_construct_data( Archive & ar, const MyClass<Real> * t, // CLASS IS TEMPLATED const unsigned int file_version) { ar << & t->myref_; }
I have got the following error (same problem with & operator): error: no match for 'operator<<' in 'ar << [...]
Hmm - assuming you're working with a compiler which supports Partial
Template Specialization
shouldn't you be using:
template
2) I there a tricky way to define this function for all type used to instantiate MyClass ?
see above
3) Is it me or this example in the documentation :
// save data required to construct instance ar << t.member1; // serialize reference to object as a pointer ar << & t.member2;
should be :
ar << t->member1; ar << & t->member2;
Archives accept objects which are passed by reference - not addresses!!
4) Should it be possible to add more examples which use templates in the library (since a lot of a macros are not available) ?
It should be possible. Of course whether such a thing happens would be an entirely different question.
Thanks in advance for your help!
You're welcome Robert Ramey
I have a class that have a reference on a vector of shared pointers to objects . ar << mct->myref_; // eliminate the &, pass the object - not the
Now I have this famous error : [...]/boost-1_33/boost/archive/detail/oserializer.hpp:566: error: incomplete type `boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value' and // a) serializing an object of a type marked "track_never" through a pointer. I don't have any object marked track_never. // b) saving an non-const object of a type not markd "track_never) In this case. I am not saving an object but a member. I reread "Compile time trap when saving a non-const value" but I don't see what to do.
codeur@altern.org wrote:
I have a class that have a reference on a vector of shared pointers to objects . ar << mct->myref_; // eliminate the &, pass the object - not the
Now I have this famous error :
[...]/boost-1_33/boost/archive/detail/oserializer.hpp:566: error: incomplete type `boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
and // a) serializing an object of a type marked "track_never" through a pointer.
I don't have any object marked track_never.
Note that certain types - e.g. primitives are marked "track_never" by default so they you don't have to explicitly mark them "track_never" to get this behavior.
// b) saving an non-const object of a type not markd "track_never)
In this case. I am not saving an object but a member. I reread "Compile time trap when saving a non-const value" but I don't see what to do.
I would guess that if you trace this error back to the original ar << ? in your code you will find that the ? is non-const. Robert Ramey
I would guess that if you trace this error back to the original ar << ? in your code you will find that the ? is non-const.
The original one is just my reference to a vector of share pointers of objects (that contains doubles, eh ?! it is track_never). And yes, of course it's not constant ;) No no no, please don't tell me that I have to wrap these doubles. I can't. It's not my code and it would be ugly.
codeur@altern.org wrote:
I would guess that if you trace this error back to the original ar << ? in your code you will find that the ? is non-const.
The original one is just my reference to a vector of share pointers of objects (that contains doubles, eh ?! it is track_never). And yes, of course it's not constant ;)
No no no, please don't tell me that I have to wrap these doubles. I can't. It's not my code and it would be ugly.
Without actually seeing the code, I can't tell you what I think you should do. Robert Ramey
participants (2)
-
codeur@altern.org
-
Robert Ramey