Original Post
Hi community. I am having problem with reference parameters between C++ and Python. I will show you the code and then I will explain the problem:
When I execute this code in the python console I get an error.
Why can I use str like an std::string&? What can I use in place?
// C++ class
class Example
{
public:
void SetHello(std::string& str)
{
str = "hello";
}
};
// Boost module
BOOST_PYTHON_MODULE(myModule_ext)
{
class_<Example> ("Example")
.def("SetHello", &Example::SetHello)
;
}When I execute this code in the python console I get an error.
>> import myModule_ext
>> c = myModule_ext.Example()
>> str = ""
>> c.SetHello(str)
Boost.Python.ArgumentError: Python argument types in
c.SetHello(Example, str)
did not match C++ signature:
SetHello(class Example {lvalue}, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > )Why can I use str like an std::string&? What can I use in place?