|
Boost Users : |
From: Joseph Hosteny (jhosteny_at_[hidden])
Date: 2006-04-28 12:46:13
Hi all,
I'm a relative newbie at using the serialization libraries, so
please go easy on me, but I'm having some troubles which I can't seem
to work out.
I have a class hierarchy that looks something like this:
A -> B -> C -> D
There is a corresponding header, and at least one source file, for
each of the four classes.
The base class, A, contains only methods, but is not a pure virtual
class. Class B contains the first set of data members in the chain
that must be serialized. Classes C and D contain some more methods
and data. All stores/loads will be handled via pointers to instances
of class D.
Now, the header file for class B contains the following:
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/base_object.hpp>
Classes B, C and D define the following as public:
friend class boost::serialization::access;
template<class Archive> void serialize(Archive &ar, const unsigned
int version);
The serialize methods for classes C and D call the base class
implementations of these methods via:
ar & boost::serialization::base_object<base_class>(*this);
Finally, the source files for classes B, C and D contain:
#include <boost/serialization/export.hpp>
BOOST_CLASS_EXPORT(class_name);
It's not clear to me, though, that I should need the EXPORT macro
since all loads/stores are done with the most derived class' pointers.
However, when I run this code, I get an exception at
oserialization.hpp line 394, which is of type
archive_exception::unregistered type.
I've looked through a lot of the documentation, but can't seem to
find out what I'm doing wrong. I've also tried explicit calls to
boost::serialization::void_cast_register<base_class, derived_class>
(), but that didn't seem to work either.
Since this is being retrofitted to a large design, I tried to
distill what I was trying to do into a sample project with just empty
classes with the same hierarchy and boot methods/macros. When I do
this, everything seems to work fine.
Does anyone have any suggestions on what I should look for that may
be screwing things up for me? I can send the sample files I used, but
since these work, I'm not sure if they will be of much help. Any
pointers will be greatly appreciated!
Thanks,
Joe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net