private member

Aarti_pl aarti at interia.pl
Fri Apr 13 01:00:28 PDT 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.
> 
> Thanks
> 

But 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


More information about the Digitalmars-d-learn mailing list