digitalmars.D - struct visibility attributes
- eugene (28/28) Aug 28 2016 Hello, everyone,
- eugene (1/1) Aug 28 2016 LDC: ldc2-0.17.1-linux-x86_64
- rikki cattermole (1/1) Aug 28 2016 Because private is to module?
- Basile B. (5/11) Aug 28 2016 inside a module you can even access to the private fields, it's
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; } }
Aug 28 2016
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.
Aug 28 2016