
On Fri, Aug 6, 2010 at 6:40 PM, Robert Ramey <ramey@rrsd.com> wrote:
gmkdroid wrote:
Hello,
I'm trying to add Boost serialization to a class which has private data members. I'm using the "non-intrusive" free save/load split method. I've added "friend class boost::serialization::access;" to my class, but I still receive a "cannot access private member..." compiler error. How can I give the load/save functions friend access to my class?
I'm not aware of any problem in this area. If you want to make a small example, we'll take a look at it.
Robert,
Here's an example of the issue I'm having: *MyObject.h* ////////////////////////////////////////////////////////////////////////////////////// #include <boost/serialization/access.hpp> class CMyObject { public: friend class boost::serialization::access; CMyObject(void) : m_nPrivateData(123) { } ~CMyObject(void) { } private: int m_nPrivateData; }; *Serializer_MyObject.h* ////////////////////////////////////////////////////////////////////////////////////// #include "MyObject.h" #include <boost/archive/xml_oarchive.hpp> #include <boost/archive/xml_iarchive.hpp> #include <boost/serialization/split_free.hpp> BOOST_SERIALIZATION_SPLIT_FREE(CMyObject) namespace boost { namespace serialization { template<class Archive> void save(Archive & ar, const CMyObject& t, unsigned int version) { ar << boost::serialization::make_nvp("CMyObject", t.m_nPrivateData); } template<class Archive> void load(Archive & ar, CMyObject& t, unsigned int version) { ar >> boost::serialization::make_nvp("CMyObject", t.m_nPrivateData); } }} // boost and serialization namespaces The program compiles fine if m_nPrivateData is made public, but fails if its private. Is there something else I should be using instead of boost::serialization::access? Thanks, Glen _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost