[C++-sig] add_property with policy?

Neal Becker ndbecker2 at gmail.com
Mon May 22 18:56:49 CEST 2006


I'd like to use add_property with a reference data member.

In the following, "getA" will work fine.  But, I'd like to make this work
with attribute access syntax:

python code:
b = B()
an_A = b.a

Anyway to make this work?  The add_property below won't compile:

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/class.hpp>
#include <boost/python/init.hpp>
#include <boost/python/return_internal_reference.hpp>

struct A {};

struct B {
  A& a;
};

A& getA (B const& b) {
  return b.a;
}

using namespace boost::python;

BOOST_PYTHON_MODULE (test1) {
  class_<B> ("B")
    .def ("getA", &getA, return_internal_reference<>()) << this is OK
    .add_property ("A", &getA) << this is NOT OK
    ;
}

/usr/local/src/boost.cvs/boost/python/detail/invoke.hpp:75: error: no match
for call to '(const
boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning<A&>)
(A&)'




More information about the Cplusplus-sig mailing list