[C++-sig] Boost.Python property definition question
Michael Wild
themiwi at users.sourceforge.net
Mon Jan 30 15:32:23 CET 2012
Hi all
I can't seem to figure out how to wrap this in Boost.Python without the
need for auxiliary functions:
#include <string>
#include <boost/python.hpp>
using std::string;
using namespace boost::python;
class A
{
string m_s;
public:
A(string const& s) : m_s(s) {}
// read-only access (
string const& s() const { return m_s; }
// read-write access
string& s() { return m_s; }
};
BOOST_PYTHON_MODULE(A)
{
class_<A> ("A", init<std::string const&>())
.add_property("s",
// this getter works fine
make_function(
(string const&(A::*)()const)&A::s,
return_value_policy<copy_const_reference>()),
// this setter fails
make_function(
(string&(A::*)())&A::s,
return_internal_reference<>()))
;
}
When I try to run the following:
import A
a = A.A("Hello")
a.s = "World!"
I get below error message:
ArgumentError: Python argument types in
None.None(A, str)
did not match C++ signature:
None(A {lvalue})
How do I solve this problem?
Thanks for any advice
Michael
More information about the Cplusplus-sig
mailing list