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
Joseph Hosteny wrote:
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
#include
Note - my suggestion is to not include *archive.hpp files in other *.hpp files. In this case I don't thnk it matters.
#include
#include 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
(*this); Finally, the source files for classes B, C and D contain:
#include
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.
I don't think that this should be necessary in your case either.
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
(), 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.
Hmm - just keep adding stuff back in until it cracks.
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!
you might try doing explicit "register" for classes A, B.. D. That should make thigns work. If it does you can either just declare victory or continue on to find the problem Robert Ramey
participants (2)
-
Joseph Hosteny
-
Robert Ramey