Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2007-06-05 15:45:02


on Mon Jun 04 2007, Alexander Eisenhuth <newsuser-AT-stacom-software.de> wrote:

> How to wrap methode Get with Boost.Python?

First, I suggest you take your question to the C++-sig
(http://www.boost.org/more/mailing_lists.htm#cplussig).

>
> class MyClass {
> public:
> MyClass();
>
> void GetX(double &pos_x);
> [...]
>
>
> I'v tried it with:
>
> .def(
> "GetX"
> , &::MyClass::GetX
> , bp::arg("")
> , bp::return_value_policy<bp::return_arg<1>() >()
>
> But when I try it in python:
>
> Boost.Python.ArgumentError: Python argument types in
> MyClass.GetX(MyClass, int)
> did not match C++ signature:
> GetX(class MyClass::LedPosition_C {lvalue}, int {lvalue} )
>
> Any ideas?

return_value_policy is only good for telling Boost.Python how to
handle the actual (non-void) return value of your C++ function. In
your case, create a thin wrapper function:

     double GetX2(MyClass& self, double pos_x)
     { self.GetX(pos_x); return pos_x; }

and wrap that instead of GetX:

           .def("GetX", GetX2)

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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