Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost-users][python] Pointer argument failed conversion?
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-04-30 15:17:55


On Thu, Apr 30, 2009 at 9:45 AM, Germán Diago <germandiago_at_[hidden]> wrote:
> Hello. After much googling I didn't find anything useful.
> My problem is:
>
>
> I have a virtual function like this
>
>
> class MyClass {
>
>      void monitor(Object * o);
> }
>
> I have wrapped another class, which inherits from Object:
>
> class Character : public Object {...};
>
> which is also exposed to python.
>
> I register my virtual function as the documentation says I have to do:
>
>
> class_<MyClass, boost::noncopyable>("MyClass").
>  def("monitor", &MyClass::monitor);
>
>
> When I try to call it from python, I get the following error:
>
> a = MyClass()
> b = Character(....)
> a.monitor(b)
>
>
>  MyClass.monitor(MyClass, Character)
> did not match C++ signature:
>    monitorizar(MyClass {lvalue}, Object *)

For it to be able to convert, two things need to be true.
  1) Object needs to be exposed to Python as well (although you might
want to use another word, 'object' is a keyword in Python and 'Object'
is awfully close to that).
  2) Character needs to be exposed to Python with Object being
specified as a baseclass in the class_ definition.

I noticed that MyClass did not specify Object as its baseclass either,
so if you intend to pass things around as their subclass type
(Object), you should tell Python that Object is its baseclass too.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net