I have a simple C++ class that I've wrapped using Boost/Python,
v1.29.0 (on Win 2K), and that has a simple accessor returning a const
ref to an internal string. In the python interpreter, the accessor
raises an exception (see below),whereas another access that returns a
copy of the string works. Could someone explain my mistake?
--bruce
------ Bar.cpp --------
#include <string>
class Bar
{
public:
Bar( const std::string& s ) : m_s( s ) {}
std::string get_s_copy() const { return m_s; }
const std::string& get_s_ref() const { return m_s; }
std::string m_s;
};
#include
import Foo bar = Foo.Bar("hello") bar.m_s 'hello' bar.get_s_copy() 'hello' bar.get_s_ref() Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: bad argument type for built-in operation