Boost logo

Boost Users :

From: Anders Sundman (anders.sundman_at_[hidden])
Date: 2007-02-02 10:40:54


Hi!

I'm having some problems grasping how the serialization library works
with respect to const/non-const data.

Ex:

Consider the following simple class that I would like to serialize:

struct Simple {
        Simple() : member(0) {}
        Simple(int m) : member(m) {}
        int member;
};
BOOST_CLASS_EXPORT(Simple);
BOOST_SERIALIZATION_SPLIT_FREE(Simple);
//BOOST_CLASS_TRACKING(Simple, boost::serialization::track_never);

namespace boost {
   namespace serialization {
     template<class Archive>
     void save(Archive & ar, const Simple & t, unsigned int version)
     {
       ar << t.member;
     }
     template<class Archive>
     void load(Archive & ar, Simple & t, unsigned int version) {
       ar >> t.member;
     }
   }
}

But when I do the serialization, strange things happen.

Ex:

const Simple s1(7);
//Simple s1(7);
boost::archive::text_oarchive oa(ss, f);
oa << s1;

The non-const alternative above doesn't work unless I do
BOOST_CLASS_TRACKING(Simple, boost::serialization::track_never);

And,

Simple * const s1 = new Simple(7);
//Simple * s1 = new Simple(7);
boost::archive::text_oarchive oa(ss, f);
oa << s1;

The non-const alternative above doesn't work even if I do
BOOST_CLASS_TRACKING(Simple, boost::serialization::track_never);

I'm obviously missing something here, please help me out.

Best regards,
Anders Sundman


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