digitalmars.D.learn - private member
Hallo, import std.stdio; class Value { private int a; } void main() { Value value = new Value; value.a=3; writefln(value.a); } "a" is a private variable, but i can set it with value.a=3; outside the class. Is there a way to avoid this. Under Attributes in the homepage i found this "Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class." But value.a=3; isn't enclosing in a class. Thanks
Apr 13 2007
nobody napisał(a):Hallo, import std.stdio; class Value { private int a; } void main() { Value value = new Value; value.a=3; writefln(value.a); } "a" is a private variable, but i can set it with value.a=3; outside the class. Is there a way to avoid this. Under Attributes in the homepage i found this "Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class." But value.a=3; isn't enclosing in a class. ThanksBut it is in same module (read: file), so there is access to private members. Just put class definition to another file... BR Marcin Kuszczak aarti_pl
Apr 13 2007