What is the current stage of @property ?
Vinod K Chandran
kcvinu82 at gmail.com
Wed Jun 10 22:25:06 UTC 2020
On Wednesday, 10 June 2020 at 21:40:44 UTC, Paul Backus wrote:
>
> The current state of @property is that it doesn't really do
> anything. D allows you to call functions without parentheses,
> and to use assignment syntax to call a single-argument
> function, so you can write getters and setters that work like
> properties even if you don't use the @property annotation:
>
>
> struct Example
> {
> private int x_;
> int x() { return x; } // getter
> void x(int n) { x = n; } // setter
> }
>
> void main()
> {
> Example e;
> e.x = 123; // calls setter
> int y = e.x; // calls getter
> }
@Paul Backus, Thanks for the explanation & code sample.
More information about the Digitalmars-d-learn
mailing list