Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2005-12-21 09:41:06


codeur_at_[hidden] 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<class Archive, class T>
 inline void save_construct_data(
  Archive & ar,
  const MyClass<T> *mct, // CLASS IS TEMPLATED
  const unsigned int file_version)
 {
  ar << mct->myref_; // eliminate the &, pass the object - not the address
of the object
 }

> 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


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