Pass by reference in Boost::Python
Posted
by Fabzter
on Stack Overflow
See other posts from Stack Overflow
or by Fabzter
Published on 2010-03-17T02:37:39Z
Indexed on
2010/03/17
2:41 UTC
Read the original article
Hit count: 620
Hi everybody. Consider something like:
struct Parameter
{
int a;
Parameter(){a = 0}
void setA(int newA){a = newA;}
};
struct MyClass
{
void changeParameter(Parameter &p){ p.setA(-1);}
};
Well, let's fast forward, and imagine I already wrapped those classes, exposing everything to python, and imagine also I instantiate an object of Parameter in the C++ code, which I pass to the python script, and that python script uses a MyClass object to modify the instance of Parameter I created at the beginning in the C++ code.
After that code executes, in C++ Parameter instance is unchanged!!! This means it was passed by value (or something alike :S), not by reference. But I thought I declared it to be passed by reference...
I can't seem to find Boost::Python documentation about passing by reference (although there seems to be enough doc about returning by reference...). Can anyone give some hint or pointer please?
© Stack Overflow or respective owner