From: David Tonge (david.tonge_at_[hidden])
Date: 2004-03-09 06:05:31
[The first time I pointed this, I forgot to add the attachment...]
I've been corresponding privately with Robert for a while about the
serialization library and he's encouraged me to start contributing to
this forum. Recently I've been looking at using shared_ptr with the
serialization tools as this is core to how I plan to use the library.
We found that it was fine to serialize a shared_ptr<A> which held an A*.
However, if there were a derived class B which was a public A then it
wasn't possible to serialize a shared_ptr<A> which held a B* into an
archive. The workaround for this, was to do this...
That seems to give the library enough information to be able to
serialize a shared_ptr<A> that holds a B*. To save typing I now use a
macro HACK_SERIALIZATION_EXPORT_SHARED_POINTER(T) which is included in
the attached file.
Now let me introduce a new problem. I seem to have uncovered another
bug. Using the workaround above I can demonstrate expected behaviour
with text archives. However, if I try to serialize a shared_ptr<A>
containing a B* to a BINARY archive then I get an assertion failure
(puzzlingly in basic_text_oarchive.hpp - line 133). I don't have any
problems serializing shared_ptr<A>s containing A*s to binary archives,
and I don't have any problems at all with text archives.
The file I've attached is a heavily modified version of
demo_shared_ptr.cpp which performs four tests:
1. Serialize shared_ptr<A>s containing A*s to and from text archives.
2. Serialize shared_ptr<A>s containing B*s to and from text archives.
3. Serialize shared_ptr<A>s containing A*s to and from binary
4. Serialize shared_ptr<A>s containing B*s to and from binary
Tests 1-3 all work fine. Test 4 fails as described.
I'd appreciate it if others with an interest in the serialization
library could take a look. I can quite believe that it's an error on my
part but I haven't been able to spot it yet.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk