structs, classes, interfaces - Part I, Motivation

Matti Niemenmaa see_signature at for.real.address
Fri Sep 7 10:46:47 PDT 2007


Steven Schveighoffer wrote:
> "Robert Fraser" wrote
>> Someone probably pointed it out in the other thread, but structs do have 
>> encapsulation/private data members.
> 
> Really?  How is this done?  I just tried this:
> 
> struct X
> {
>   private int _y;
>   int y()
>   {
>     return _y;
>   }
> }
> int main(char[][] args)
> {
>   X x;
>   x._y = 5;
>   return 0;
> }
> 
> 
> Compiler doesn't complain...
> 

In D, protection attributes apply only across modules. In the same module,
everything is public.

If you've used C++, think of it as everything in a module being implicitly
"friend" with each other.

-- 
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi



More information about the Digitalmars-d mailing list