Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Registering/exporting shared_ptr<T> in a library
From: Martin Weinberg (martin.weinberg_at_[hidden])
Date: 2013-12-28 19:02:18


On 12/28/2013 06:34 PM, Robert Ramey wrote:
>
>
> On Saturday, December 28, 2013 2:15:44 PM UTC-8, Martin Weinberg wrote:
>
> I have a shared library for derived and base classes. My code passes
> instances of derived classes T using boost::shared_ptr<B> to the base
> class. This all works as expected.
>
> I've used the BOOST_CLASS_EXPORT_KEY and BOOST_CLASS_EXPORT_IMPLEMENT
> macros to register both the classes Tand shared_ptr<T> typedefs to
> all
> the classes.
>
> If I attempt to serialize a base class pointer,
> boost::serialization can
> not find the serialize member for the shared_ptr to the derived
> class.
>
>
> a) double check the documentation boost/serialization/case
> studies/shared_ptr<T> revisited
>
> b) Make sure you'r doing the following
>
> class A {...};
> class B : public A {...}
> ...
> A * = new B; // note we create a B and cast the address to an A* !!!
>
> ... should be no problem from here on out.
>
> Robert Ramey

Thanks. What I'm doing is:

shared_ptr<A> t(new B);

and then:

ar & A;

It's ok if I put:

BOOST_CLASS_EXPORT(shared_ptr<A>)
BOOST_CLASS_EXPORT(shared_ptr<B>)

in the caller but not if I put them in the library. Trying to
understand if there's a way to put registration in the library rather
than the main source.



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