Virtual function issue.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Virtual function issue.

Kamal Mansouri
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++ passed back 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.



------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Virtual function issue.

John Reid-3
Have you tried posting to the Python C++ group? You may get more
responses there.

[hidden email]

John.



Kamal wrote:

> 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++ passed back 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.
>
>
>
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Boost-langbinding mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
Loading...