I am trying to make a simple call by reference from python to a C ++ class method.
My C ++ code looks like this:
class Foo { protected: int _internalVal; public: Foo() : _internalVal(5){} void getVal(int& val_io) {val_io = _internalVal;} void getValDoesNothing(int val_io) {val_io = _internalVal;} }
My wrapper code that compiles in order:
BOOST_PYTHON_MODULE(libBar) { boost::python::class_<Foo>("Foo") .def("getVal", &Foo::getVal) .def("getValDoesNothing", &Foo::getValDoesNothing); }
However, when I make the following python calls:
In [1]: import libBar In [2]: f = libBar.Foo() In [3]: f Out[3]: <libBar.Foo at 0x2b483c0> In [4]: val = int() In [5]: #next command is just to check function signature type In [6]: f.getValDoesNothing(val) In [7]: f.getVal(val) --------------------------------------------------------------------------- ArgumentError Traceback (most recent call last) <ipython-input-5-531e4cea97c2> in <module>() ----> 1 f.getVal(val) ArgumentError: Python argument types in Foo.getVal(Foo, int) did not match C++ signature: getVal(Foo {lvalue}, int {lvalue})
I work with a library that I do not control, so changing getVal to return a value is not an option.
Is there a way to get the latest Python command to work?
Iβll even take a fix that does not change the Python variable, but still allows you to call a function call.
source share