`restricted` member variables

forkit forkit at gmail.com
Thu Jun 23 11:23:43 UTC 2022


On Thursday, 23 June 2022 at 11:16:39 UTC, forkit wrote:
>

look ma...

// ----
module test;
@safe:

import std;

class Base
{
     private(this) int x = 100;
     private int y = 200;
}

class Derived : Base
{
     //public int x = 200;
}

void main()
{
     Derived d = new Derived();
     writeln(d.x);
     writeln(d.y);
}
// ------


> dmdnew -preview=privateThis privatethis.d privatethis.d(21): 
> Error: no property `x` for type `test.Derived`

woohoo! 6 years in the making!!!

(just to do what I've able to do for 20+ years in other 
languages).



More information about the Digitalmars-d mailing list