Boost logo

Boost :

Subject: Re: [boost] [boost.Serialization V1.42.0] Question about BOOST_SERIALIZATION_SPLIT_FREE and non-public members
From: gmkdroid (gmkdroid_at_[hidden])
Date: 2010-08-06 15:59:44


On Thu, Aug 5, 2010 at 8:03 PM, Stefan van Kessel <van_kessel_at_[hidden]>wrote:

> I'm afraid declaring boost::serialization::access a friend is only helpful
> if you choose the intrusive approach and your serialize member function is
> not public. If you need the members to be non-public and a "non-intrusive"
> approach, it seems you have to use a workaround like a derived "accessor
> class" that exposes the private members. See
> http://stackoverflow.com/questions/1687579/boost-serialization-access-to-protected-datafor an example.
>
> Have a nice day,
> Stefan
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

Stefan,
Thanks for the response. Unfortunately, I think the workaround from
stackoverflow would only allow me to access protected members -- not private
ones.

I did come up with another option that seems to be working for me. I
created a save_handler(xml_oarchive& oa, const CMyObject& rObj, const
unsigned int version) and load_handler(xml_iarchive& ia, CMyObject& rObj,
const unsigned int version) function. I gave these two functions friend
access to my class being serialized so they have access to the private
members. I have the split/free functions, boost::serialization::save() and
boost::serialization::load(), call my handler functions to do the actual
serialization.

Glen


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk