www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - 126 - Nested class privacy issues

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
Outer classes can't access inner classes' private members.

class A
{
 this()
 {
  b=new B;
 }

 class B
 {
  private int mX;
 }
 B b;

 void something()
 {
  int x=b.mX; // illegal
  C c=new C;
  int y=c.mY; // legal
 }
}

class C
{
 private int mY;
}

You'll notice that I can't access b's mX, but I can access C's mY.

I thought that if classes were in the same module (and _especially_ in the 
same class!) that private members were accessible in that module. 
Jun 09 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Jarrett Billingsley wrote:
<snip>
 I thought that if classes were in the same module (and _especially_ in the 
 same class!) that private members were accessible in that module. 
Oh dear, sounds like an old bug has come back. http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/2270 view-source:http://svn.kuehne.cn/dstress/run/private_02.d view-source:http://svn.kuehne.cn/dstress/run/private_03.d Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jun 10 2005