Boost logo

Boost Users :

Subject: [Boost-users] splitting non intrusive serialization into save/load
From: Babineau, Denis (Denis.Babineau_at_[hidden])
Date: 2010-06-04 11:26:50


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.



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