[C++-sig] Re: cross-module shared_ptr downcast

David Abrahams dave at boost-consulting.com
Fri Jun 27 22:47:01 CEST 2003


Jon Anderson <janders at users.sourceforge.net> writes:

> I have a Container that holds shared_ptr's to a Base class.  I can 
> successfully add and retrieve shared_ptrs to a Derived class, properly 
> downcasted on retrieval, as along as the bindings for both the Base and 
> Derived class are defined in the same module.  However, when I have the Base 
> class bindings defined in module A, and the Container and Derived class 
> bindings defined in module B, the down cast no longer happens.  Each module 
> is a separate .so.
>
> Should this work, or am I limited to having them all in the same module in 
> order to make the downcasts work?

Whether or not this will work is heavily dependent on your compiler's
ABI.  In general, if you want to get it to work, you have to get the
.sos to link to one-another, or to a common shared library which
contains the base class's RTTI info.  How to generate the RTTI info is
again dependent on your compiler's ABI, but usually it's enough to
define one of the base class' member functions in the common shared
library.

HTH,
-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list