[Issue 8006] Implement proper in-place-modification for properties

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Oct 9 05:23:58 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=8006

mikey <abc.mikey at googlemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |abc.mikey at googlemail.com

--- Comment #5 from mikey <abc.mikey at googlemail.com> ---
As a beginner this is a source of some confusion for me. Ideally the
implementation details of a property vs a member variable should be transparent
to me as a user of a given object.




class Test {
private:
    int _val, _val2;

public:

    @property int val() { return _val; }
    @property void val(int val) { _val = val; }

    @property auto ref val2() { return _val2; }
}

void main() {

    auto t = new Test;
    //t.val += 100; // BAD - not an lvalue

    t.val(t.val + 100); // probably preferable to misleading syntax

    t.val2 += 200; // OK - but inconsistent

    import std.stdio : writefln;
    writefln("val: %d, val2: %d", t.val, t.val2);
}

~

--


More information about the Digitalmars-d-bugs mailing list