Boost.Serialization: Error on Calling Class Method during serialization process
I have the following problem when I try to call method in "TestSerialize" class during serialization process. Here is my code: class TestSerialize { public: std::string GetVal() { return Val + "abc"; } void SetVal(std::string tVal) { Val = tVal.substr(0, 2); } protected: std::string Val; friend class boost::serialization::access; template<class Archive> void save(Archive & ar, const unsigned int version) const { using boost::serialization::make_nvp; std::string tVal = GetVal(); // Error here ar & make_nvp("SC", tVal); } template<class Archive> void load(Archive & ar, const unsigned int version) { using boost::serialization::make_nvp; std::string tVal; ar & make_nvp("SC", tVal); SetVal(tVal); } BOOST_SERIALIZATION_SPLIT_MEMBER(); }; int main() { TestSerialize tS; std::ofstream ofs("test.xml"); boost::archive::xml_oarchive oa(ofs, boost::archive::no_header); oa << BOOST_SERIALIZATION_NVP(tS); ofs.close(); return 0; } The error that I encountered is: 'TestSerialize::GetVal' : cannot convert 'this' pointer from 'const TestSerialize' to 'TestSerialize &' This error only happens on "save" but not "load" I wonder why I get this error. I would like to know what Boost.Serialization do such that we have these two different behaviors. I use Boost Library 1.47.0 Regards,
Hazrat Pradipta Ranjali wrote:
int main() { const TestSerialize tS;
I wonder why I get this error. I would like to know what Boost.Serialization do such that we have these two different behaviors. I use Boost Library 1.47.0
There is an explanation of thi s in the manual. Robert Ramey
participants (2)
-
Hazrat Pradipta Ranjali
-
Robert Ramey