Re: [Boost-users] serialization on const member and map<const CLASS*, CLASS>

Please take note that even the following simplest form won't work. Here is the full source code. Any suggestion? Thank you very much! #include <iostream> #include <sstream> #include <fstream> using namespace std; #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> class dd { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & i; } int i; }; class dummy { public: dummy() : d(0){} ~dummy(){} private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & const_cast<dd *>(d); } const dd *d; }; int main() { const dummy w; dummy r; // make an archive std::ofstream ofs("dummy"); boost::archive::text_oarchive oa(ofs); oa << w; std::ifstream ifs("dummy"); boost::archive::text_iarchive ia(ifs); ia >> r; } c:\Documents and Settings\yccheok\Desktop\xxx\main.cpp(34): error C2679: binary '&' : no operator found which takes a right-hand operand of type 'dd *' (or there is no acceptable conversion) __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Here is the full source code. Any suggestion? Thank you very much!
Try the change below: Robert Ramey
#include <iostream> #include <sstream> #include <fstream>
using namespace std;
#include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp>
class dd { private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & i; }
int i; };
class dummy { public: dummy() : d(0){} ~dummy(){}
private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) {
//*** replace this:
//ar & const_cast<dd *>(d);
//*** with this //ar & const_cast<dd * &>(d);
}
const dd *d; };
int main() { const dummy w; dummy r;
// make an archive std::ofstream ofs("dummy"); boost::archive::text_oarchive oa(ofs);
oa << w;
std::ifstream ifs("dummy"); boost::archive::text_iarchive ia(ifs);
ia >> r; }
c:\Documents and Settings\yccheok\Desktop\xxx\main.cpp(34): error C2679: binary '&' : no operator found which takes a right-hand operand of type 'dd *' (or there is no acceptable conversion)
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
participants (2)
-
Cheok Yan Cheng
-
Robert Ramey