Boost logo

Boost :

Subject: Re: [boost] [serialization] working around the pointer_conflictexception?
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-09-01 12:38:34


T. Farago wrote:
> I have implemented the serialise library of BOOST to my own classes.
> Using a single entry point it recursively goes through every member
> and saves the values. Of course initial implementation yielded the
> pointer_conflict expression as for example while going through
> objects A,B,C object A may have a pointer to B, and only afterwards
> is B actually saved.
>
> I tried - and thought - to fix this by using a two-phased approach.
> First I save all the actual objects from the entry point, secondly
> only the pointers. eg
>
> save_objects = true;
> ar & my_object;
> save_objects = false;
> ar & my_objects;
>
> and inside every class:
> class A {
> public:
> int a;
> int *b;
> serialise() {
> if (save_objects) {
> ar & a;
> } else {
> ar & b;
> }
> }
> };
>
> This seemed sound but only during debugging did I realise that the
> second run of the serialiser doesn't do anything since my_object is
> already saved. So this won't work.
>
> Does anyone have better ideas on solving this problem, or has
> encountered and already solved this issue?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk