
Dear group, I am trying to provide generic toString/fromString methods (to provide an interface to SWIG/Python serialization), which I'd like to implement in a base class CSGObject (from which all other classes are derived), such that the correct serialization code is called each time. After a bit of fiddling around (and with the help of the archive of this mailing list) I've got the toString method to work. However, things don't seem to be as straight for the fromString method. The following code illustrates what I'd like to do: virtual std::string toString() const { std::ostringstream s; boost::archive::text_oarchive oa(s); oa << this; return s.str(); } virtual void fromString(std::string str) { std::istringstream is(str); boost::archive::text_iarchive ia(is); //cast away constness CSGObject* tmp = const_cast<CSGObject*>(this); ia >> tmp; *this=*tmp; } However, although the correct serialization methods get called, only the information contained in the base class gets restored correctly, but none of the fields in any derived classes. My C++ is quite rusty, but I believe this is because *this is not a pointer and is thus statically bound. I hope there is a solution to this - how would you implement a fromString method like this? Is this even possible? What are the alternatives? Hints would be appreciated! Thank you, Chris