Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 28, 2016 struct visibility attributes | ||||
---|---|---|---|---|
| ||||
Hello, everyone, i looked at https://dlang.org/spec/attribute.html#visibility_attributes but it says nothing about visibility attributes in structs. The question is: why is the code compiled by ldc and working: import std.stdio:writeln; void main() { test_struct testStruct = test_struct(); testStruct.add_to_x; // add_to_x is private testStruct.add_to_x; writeln("x=", testStruct.x); // x is private } struct test_struct { private: int x; void add_to_x() { x++; } public: int get_x() { return x; } } |
August 28, 2016 Re: struct visibility attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to eugene | LDC: ldc2-0.17.1-linux-x86_64 |
August 28, 2016 Re: struct visibility attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to eugene | Because private is to module? |
August 28, 2016 Re: struct visibility attributes | ||||
---|---|---|---|---|
| ||||
Posted in reply to eugene | On Sunday, 28 August 2016 at 09:32:11 UTC, eugene wrote: > Hello, everyone, > i looked at https://dlang.org/spec/attribute.html#visibility_attributes but it says nothing about visibility attributes in structs. inside a module you can even access to the private fields, it's clearly written in the specs: > Symbols with private visibility can only be accessed from within the same module. Some languages have a "strict private" protection level to ensure a proper usage of the fields inside a same module, but not D. |
Copyright © 1999-2021 by the D Language Foundation