Thread overview
struct visibility attributes
Aug 28, 2016
eugene
Aug 28, 2016
eugene
Aug 28, 2016
rikki cattermole
Aug 28, 2016
Basile B.
August 28, 2016
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
LDC: ldc2-0.17.1-linux-x86_64


August 28, 2016
Because private is to module?
August 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.