|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-01-10 20:00:02
"Bruce Lowery <bruce_lowery_at_[hidden]>" <bruce_lowery_at_[hidden]> writes:
> 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?
C++ strings are exposed to Python as Python strings by default.
return_internal_reference<> builds a Python object around a pointer to
the C++ result object (which must have a class_<> wrapper somewhere)q,
and applies some lifetime management to keep the "self" object alive
as long as the Python result is alive. If you want it to work, you
could write class_<std::string>("string")... to create a std::string
wrapper. I'm not sure you'd be getting the result you want, though:
it wouldn't be a Python string. You could expose enough of
std::string's operators to make it look like a Python string, of
course.
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net