On Sat, 11 Dec 2004 21:43:11 +0100, danny van elsen
<da*************@hotmail.com> wrote:
hello all,
in my application, I want to save the state of a number of classes to disk: what would be the best way to do this?
right now, I'm hard coding the fields of the classes, but of course after
every change to the classes, I also have to adapt the 'save' method. Is there a better way, perhaps using some kind of reflection?
I've searched boost.org for reflection, but there don't seem to be ready made classes?
One approach is to only ever have one data member, a boost::tuple.
That's not nice though, since you have to add a load of private
accessor methods really to avoid nasty syntax (and you may need
const/non-const overloads). Alternatively, accept the small
maintenance overhead (which does give you backwards compatibility and
versioning, unlike if you use reflection directly as is often done in
Java), and use the boost serialization library.
Tom