[C++-sig] Smart pointer, polymorphism issue
Kamal Mansouri
kranar at hotmail.com
Tue Mar 17 23:30:21 CET 2009
Hello,
I have created a Python wrapper using a custom smart pointer that
is defined
in the following manner:
class_<EventWrapper,
noncopyable, Ptr<EventWrapper>>("Event", init<>())
.def("f", &Event::f, &EventWrapper::default_f).
implicitely_convertible<Ptr<EventWrapper>, Ptr<Event>>();
register_ptr_to_python<Ptr<Event>>();
Now... when I subclass
this in Python like so:
class MyEvent(Event):
def f(self):
return 42
I can use MyEvent as expected only within Python code... when I
pass an
instance of MyEvent to C++, and then C++ passes MyEvent back
to
Python, I no longer am able to call the overridden method f in
Python.
Calling f in Python invokes Event::f, as opposed to
MyEvent.f
This only happens when I construct MyEvent in Python code, pass
the instance
to some C++ code, and have the C++ code pass back the
MyEvent instance
back to Python.
Any ideas why this may
be?
Thanks.
_________________________________________________________________
Share photos with friends on Windows Live Messenger
http://go.microsoft.com/?linkid=9650734
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090317/b8193ff1/attachment-0001.htm>
More information about the Cplusplus-sig
mailing list