struct visibility attributes

eugene via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 28 02:32:11 PDT 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;
         }
}




More information about the Digitalmars-d mailing list