tupleof seems to break encapsulation
simen.kjaras at gmail.com
Fri Sep 4 10:43:48 UTC 2020
On Friday, 4 September 2020 at 10:16:47 UTC, 60rntogo wrote:
> Consider the following code.
> module foo;
> struct Foo
> private int i;
> void main()
> import std.stdio;
> import foo;
> auto x = Foo();
> // ++x.i;
> As expected, the commented line does not compile. If I
> uncomment it, I get the error "no property i for type foo.Foo".
> However, the rest of the code compiles just fine and outputs:
> This appears to defeat the purpose of declaring i private. What
> am I missing?
It's a known issue: https://issues.dlang.org/show_bug.cgi?id=19326
There are some very good reasons to allow some access to private
fields, though it should be more limited than is currently the
More information about the Digitalmars-d-learn