Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2005-12-13 18:11:09


Malte Clasen <news_at_[hidden]> writes:

> Hi,
>
> let's say we've got the following C++ classes:
>
> class position {
> public:
> float get_height() const;
> void set_height(float value);
> private:
> float height_;
> };
>
> class object {
> public:
> position get_position() const;
> void set_position(const position& value);
> private:
> position pos_;
> };
>
> This design is not fixed, but right now this is the starting point. When
> I added the boost.python interface to it using add_property(), I quickly
> noticed that using these classes feels somehow unpythonic: I cannot
> modify the height of the position of an object using
>
> obj.pos.height = x
>
> because get_position() returns the position by value, so the following
> set_height modifies a temporary instance of position. The work-around on
> the python side looks clumsy:
>
> Is there a common solution to this problem? Does my proxy approach seem
> reasonable?

http://thread.gmane.org/gmane.comp.python.c++/8966 should help. Use
return_internal_reference.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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