Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost serialization] non intrusive & derivated class
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-06-24 12:33:20


agrosjea wrote:
> BOOST_SERIALIZATION_BASE_OBJECT_NVP isnt working in a non intrusive
> case, since the macro uses this.

Hmmm - this never came up before. But look likes your correct. The
definition
of BOOST_SERIALIZATION_BASE_OBJECT_NVP is

#define BOOST_SERIALIZATION_BASE_OBJECT_NVP(name) \
    boost::serialization::make_nvp( \
    BOOST_PP_STRINGIZE(name), \
    boost::serialization::base_object<name >(*this) \
)

So you might try:

template<class Archive>
void save(Archive &ar, const my_class & t, const unsigned version){
    ar << boost::serialization::make_nvp(
        "base_class_name",
        boost::serialization::base_object<my_class &>(t)
    );
    .... // member variables of my_class
};

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