encapsulation

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu Mar 22 01:32:32 PDT 2007


David B. Held wrote:
> arun s wrote:
>> class A {      private int c=0;  }
>>
>>
>> void main() {
>>       A a = new A();
>>       printf("%d",a.c);
>> }
>>
>> consider the above code snippet..... y there is no error in printf 
>> statement a.c , since attribute "c" is private ???? 
> 
> In D, 'private' really means 'package private', like Java's 'package' 
> visibility (or 'default' visibility), not like C++'s 'private'.  While I 
> prefer tight visibility semantics, I think this is a reasonable compromise.
> 
> Dave

Actually its module-private, with the seperate 'package' attribute providing package-level 
visibility.  Unfortunately 'package' currently suffers in that such declerations are 
hidden from sub-packages.

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list