structs, classes, interfaces - Part I, Motivation

Steven Schveighoffer schveiguy at yahoo.com
Fri Sep 7 10:37:34 PDT 2007


"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...

I also noticed on this page http://www.digitalmars.com/d/struct.html
that structs don't allow "hidden members" but offer "member protection."  As 
these two things seem equivalent to me, I was wondering if someone could 
explain the difference.

-Steve 





More information about the Digitalmars-d mailing list