[C++-sig] smart pointers, polymorphism

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Fri Jul 11 08:37:22 CEST 2003


>>>>> "DL" == Dusty Leary <dleary at ttlc.net> writes:
[snip]

    DL> class_<A, boost::intrusive_ptr<A> >("A").....; class_<B,
    DL> boost::intrusive_ptr<B> >("B").....;

    DL> How can I make it so that the "polymorphic search" succeeds,
    DL> in matching intrusive_ptr<B> against A* parameters?

AFAIK, 

 class_<B, bases<A>, boost::intrusive_ptr<B> >("B").....;

should do the trick.  But note that if you want to subclass these in
Python and have your C++ code use the overriden virtual functions from
Python you'll need to create a wrapper for the classes as described
here:

 http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html

The intrusive_ptr should be handled automatically by Boost.Python.
Look here:

 http://www.boost.org/libs/python/doc/v2/class.html#class_-spec

for more details.


HTH,
prabhu




More information about the Cplusplus-sig mailing list