Privatize a few members to allow messing with them #11353

Stanislav Blinov stanislav.blinov at gmail.com
Tue Jun 30 20:01:43 UTC 2020


On Tuesday, 30 June 2020 at 19:58:05 UTC, matheus wrote:

> +            loc.linnum = loc.linnum + incrementLoc;
>
> This works because it was declared:
>
> void linnum(uint rhs) { _linnum = rhs; }
>
> Right?

Almost. Given these definitions:

@safe @nogc pure @property
{
     const uint linnum() { return _linnum; }
     void linnum(uint rhs) { _linnum = rhs; }
}

This:

loc.linnum = loc.linnum + incrementLoc;

is rewritten as:

loc.linnum(loc.linnum() + incrementLoc);


More information about the Digitalmars-d-learn mailing list