[C++-sig] problems downcasting from C++ base class intrusive pointers to Python derived instances.
Lucio Moser
lucio at image-engine.com
Tue Feb 13 20:54:20 CET 2007
> I don't know how this possible. It does not matter what smart pointer you use
> you cannot downcast to Python class. This is just impossible. You only
> can downcast to the class defined in C++.
>
Well, the reality is, it works for shared_ptr. If you compile the code
you'll see it. Whatever boost.python is doing, it knows to downcast the
shared_ptr for a C++ class to a python derived class. There should be a
solution for intrusive_ptr too.
> After reading your post few times, I think I understand your question
> and unfortunately I cannot help.
> I have 2 advices to you:
>
> Try to use class wrapper(
> http://boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions
> ). May be this will help.
>
> Try to introduce pure virtual function to your classes. May be
> compiler will find
> for you the places, you make class "slicing"(
> http://www.informit.com/articles/printerfriendly.asp?p=31529&rl=1 )
>
>
Thank you for the links. I'll check them out in detail. Although they do
not seem related to the problem I'm facing. I'm not trying to redefine
the virtual methods of the C++ class on the python derived class. I'm
just creating a very simple derived python class, and I'm not getting it
back if I send it to the C++ functions.
This is my simple Python derived class. I'm not redefining any method on it.
class Derived2(Derived):
pass
More information about the Cplusplus-sig
mailing list