structs, classes, interfaces - Part I, Motivation

Lutger lutger.blijdestijn at gmail.com
Fri Sep 7 10:52:09 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;
> }

Try declaring the struct in another module. Within a module, everybody 
is a friend, including classes.



More information about the Digitalmars-d mailing list