splitting non intrusive serialization into save/load

Hi I'm trying to serialize a class using non intrusive templates since I can't modify the class. The class has proper set/gets but doesn't expose the data directly so I would need to use the save/load method which requires a macro to be defined in the class but, again, I can't modify the class. Looking at the code, I tried the following to have the save/load implemented outside but get the following error with MSVC 7.1 (boost version 1.39). Is there any way to accomplish what I'm trying to do here? Thanks Denis error C2270: 'save' : modifiers not allowed on nonmember functions sample implementation: class MyClass { public : int GetValue() const; public : void SetValue(int v); private: int m_Value; }; ... namespace boost { namespace serialization { template <class Archive> void save(Archive & ar, MyClass & c, const unsigned int version) const { int v = c.GetValue(); ar & v; } template <class Archive> void load(Archive & ar, MyClass & c, const unsigned int version) { int v; ar & v; c.SetValue(v); } template <class Archive> void serialize(Archive & ar, MyClass & c, const unsigned int version) { boost::serialization::split_member(ar, c, version); } }} CONFIDENTIALITY NOTICE: The contents of this email are confidential and for the exclusive use of the intended recipient. If you receive this email in error, please delete it from your system immediately and notify us either by email, telephone or fax. You should not copy, forward, or otherwise disclose the content of the email.

AMDG Babineau, Denis wrote:
error C2270: 'save' : modifiers not allowed on nonmember functions
<snip>
namespace boost { namespace serialization { template <class Archive> void save(Archive & ar, MyClass & c, const unsigned int version) const;
void save(Archive & ar, const MyClass & c, const unsigned int version);
template <class Archive> void serialize(Archive & ar, MyClass & c, const unsigned int version) { boost::serialization::split_member(ar, c, version); } }}
Use split_free instead of split_member. In Christ, Steven Watanabe

Thanks! split_free worked like a charm! I managed to find it in the documentation after reading your post; I was looking in the wrong sections (tutorials talked about split_member but not split_free which threw me off). -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Friday, June 04, 2010 12:47 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] splitting non intrusive serialization into save/load AMDG Babineau, Denis wrote:
error C2270: 'save' : modifiers not allowed on nonmember functions
<snip>
namespace boost { namespace serialization { template <class Archive> void save(Archive & ar, MyClass & c, const unsigned int version) const;
void save(Archive & ar, const MyClass & c, const unsigned int version);
template <class Archive> void serialize(Archive & ar, MyClass & c, const unsigned int version) { boost::serialization::split_member(ar, c, version); } }}
Use split_free instead of split_member. In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users CONFIDENTIALITY NOTICE: The contents of this email are confidential and for the exclusive use of the intended recipient. If you receive this email in error, please delete it from your system immediately and notify us either by email, telephone or fax. You should not copy, forward, or otherwise disclose the content of the email.
participants (2)
-
Babineau, Denis
-
Steven Watanabe