private attribute don't function?

Zhouxuan pycerl at qq.com
Sat Oct 5 08:24:20 PDT 2013


On Saturday, 5 October 2013 at 15:21:46 UTC, David Nadlinger 
wrote:
> On Saturday, 5 October 2013 at 15:19:34 UTC, Zhouxuan wrote:
>> import std.stdio;
>>
>> class A
>> {
>> 	private int j = 1;
>> 	
>> 	private
>> 	{
>> 		int k = 2;
>> 	}
>> 	
>> private:
>> 	int i = 0;
>> }
>>
>> void main()
>> {
>> 	A a = new A;
>> 	writeln(a.i);
>> 	writeln(a.j);
>> 	writeln(a.k);
>> }
>
> In D, "private" means "private to the current module". If you 
> try accessing the fields from another module, you'll see that 
> it doesn't work.
>
> In the future, please consider posting similar question in 
> digitalmars.D.learn.
>
> David

Okay, got it, thank you!


More information about the Digitalmars-d mailing list