[C++-sig] lvalue converter - pass by reference (non-const)

Moe Goldberg goldberg at coredp.com
Thu May 15 17:02:40 CEST 2008


That's a good point, I guess I was really thinking more of my case, 
where the python object that I am converting to/from contains a 
reference to the C++ object that I am converting from/to

e.g.

struct py_obj
{
    py_obj() {}
    py_obj(const my_cpp_obj& value) : value_(value) {}
    cpp_obj& value_;
};

void my_func(cpp_obj& co)
{
    co.modify();
}

then in python I want to call:
 >>>  po = my_mod.py_obj()
 >>>  my_mod.my_func(po)

Is there a way to do this without manually wrapping myfunc?

Hans Meine wrote:

>Am Mittwoch, 14. Mai 2008 22:55:25 schrieb Moe Goldberg:
>  
>
>>and then try to run it as follows:
>> >>> import custom_string
>> >>> mystr="123"
>> >>> custom_string.size(mystr)
>>
>>Traceback (most recent call last):
>>  File "<stdin>", line 1, in ?
>>Boost.Python.ArgumentError: Python argument types in
>>    custom_string.size(str)
>>did not match C++ signature:
>>    size(sandbox::(anonymous namespace)::custom_string {lvalue})
>>    
>>
>
>You're not passing a custom_string, but a python str-object (which is 
>furthermore immutable).  How should the BPL extract a reference to a 
>custom_string from a str-object?
>
>  
>



More information about the Cplusplus-sig mailing list