[C++-sig] Calling a C++ function with arguments by reference (lvalues)

Oded Padon opadon at yahoo.com
Mon Aug 2 13:27:31 CEST 2010


Hello everybody,

I'm very new to Boost.Python, and I just spent hours trying to do something trivial, and couldn't get it. The C++ code is:

void add(int const a, int const b, int const& c)
{
    c = a + b;
}

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("add", add);
}

When I tried to call this function from python I got the following error:
>>> import hello_ext
>>> x = int()
>>> y = int()
>>> z = int()
>>> hello_ext.add(x,y,z)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    hello_ext.add(int, int, int)
did not match C++ signature:
    add(int, int, int {lvalue})

How can I get this to work?
I must emphasize that I wish to have functions that get arguments by reference and change them. Returning the values using the return mechanism isn't what I want to do (I have functions that get and set many many arguments, and I hardly wish to rewrite them).

Thanks,
Oded


      



More information about the Cplusplus-sig mailing list