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.