[C++-sig] contained structure access

David Abrahams dave at boost-consulting.com
Thu Nov 14 18:30:15 CET 2002

David Abrahams <dave at boost-consulting.com> writes:

> Graeme Lufkin <gwl at u.washington.edu> writes:
>> 	I've found some strange (I think) behavior in Boost.Python, and I've
>> boiled it down to the example below.

>> 	I can create variables of type Atom, and get/set it's 'x' member
>> variable fine.  I can also create variables of type Holder, and get/set
>> its 'a' member variable (of type Atom).  However, when I try to modify
>> the 'x' of the Holder's Atom, it is ignored.  I can recreate this
>> situation using regular 100% Python classes, and it works as expected. 
>> So, what am I doing wrong?
> you'll see that make_getter with one argument uses the default call
> policies, which copy of all return values. What's happening is that
> the x member is getting set in the copy.
> Instead, you could use
>    this->add_property(
>         name
>         , make_getter(&Holder::a, return_internal_reference<>())
>         , make_setter(&Holder::a));
> Which should get you the behavior you want. I'll look into fixing it
> so this is no longer needed, if I can find a few minutes to spend on
> it.

Done. See

                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

More information about the Cplusplus-sig mailing list