Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 24 08:07:55 PDT 2016
On Tuesday, May 24, 2016 10:10:16 Steven Schveighoffer via Digitalmars-d-learn
wrote:
> A while ago, I discovered that this works.
>
> class C {
> union
> {
> private int _my_var;
> public const int my_var;
> }
> void do_something() { _my_var = 4; }
> }
Yeah. That's basically what Rebindable does, though in its case, it's not
really allowing you to mutate any data, just what the reference refers to.
Regardless, it does seem like a hole in the type system.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list