Boost logo

Boost Users :

From: Johan Franzén (johan_at_[hidden])
Date: 2007-06-27 15:10:14


> Hello,
>
> I'm having an issue with serializing derived classes from a base class
> pointer. I think I've narrowed it down to the simplest possible code. I
> get an "unregistered class" exception at runtime even though I've
> registered the derived class with BOOST_CLASS_EXPORT. Here's the code:
>
[ snip ]
> -----------------------------------------------
>
> X.hpp:
>
> #pragma once
>
> #include <boost/serialization/base_object.hpp>
> #include "A.hpp"
>
> class X : public A
> {
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive & ar, const unsigned int)
> {
> ar & boost::serialization::base_object<A>(*this);
> }
> };
>
> ------------------------------------------------
>
> X.cpp:
>
> #include "X.hpp"
>
> #include <boost/serialization/export.hpp>
>
> BOOST_CLASS_EXPORT(X)
>
> -----------------------------------------------
>
> As you can see, I don't have BOOST_CLASS_EXPORT in the X.hpp header.
> This is the way I originally had it but then I got multiple definition
> link errors when more than one class derived from A. The suggestion in
> the serialization docs was to move the macro to a .cpp file.
[ snip ]

Hello Avery,

I suspect You need to BOOST_CLASS_EXPORT(A) as well, since You do
try to serialize an A in X's serialize() method. This is was I
ended up doing when serializing a hierarchy of derived classes and
a base class. I'm not sure how to do that in Your case, since I
had all classes and all BOOST_CLASS_EXPORT macros in a single header
file.

HTH,
Johan Franzén


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