Properties: a.b.c = 3
Zhenyu Zhou
rinick at gmail.com
Wed Jul 29 17:54:29 PDT 2009
Chad J Wrote:
> Currently there are some cases where the current paradigm forces you to
> do that kind of work by hand:
>
> struct Rectangle
> {
> float x,y,w,h;
> }
> class Widget
> {
> Rectangle _rect;
> Rectangle rect() { return _rect; }
> Rectangle rect(Rectangle r) { return _rect = r; }
> }
> void main()
> {
> auto widget = new Widget();
>
> // DOES WORK:
> auto tmp = widget.rect;
> tmp.w = 200;
> tmp.h = 100;
> widget.rect = tmp;
>
> // DOES NOT WORK:
> // widget.rect.w = 200;
> // widget.rect.h = 100;
> }
What about:
class Widget
{
Rectangle _rect;
immutable(Rectangle) rect() const { return _rect; }
Rectangle rect(Rectangle r) { return _rect = r; }
}
More information about the Digitalmars-d
mailing list