Re: [Boost-users] [serialization] Registering/exporting shared_ptr<T> in a library
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.
I'm inlining some example code. Compile with CXXFLAGS=-DIN_LIBRARY for the problematic behavior and working version without IN_LIBRARY defined. Then run "test". Makefile http://boost.2283326.n4.nabble.com/file/n4657106/Makefile TestClasses.H http://boost.2283326.n4.nabble.com/file/n4657106/TestClasses.H TestClasses.cc http://boost.2283326.n4.nabble.com/file/n4657106/TestClasses.cc test.cc http://boost.2283326.n4.nabble.com/file/n4657106/test.cc test2.cc http://boost.2283326.n4.nabble.com/file/n4657106/test2.cc -- View this message in context: http://boost.2283326.n4.nabble.com/serialization-Registering-exporting-share... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (1)
-
Martin Weinberg