November 14, 2005
I hope this is the proper place to post this.  I noticed that the compiler ran fine with this bit of code.

import std.c.stdio;

class Base
{
private:
int x;
}

class Sub: Base
{
public:
void Write()
{
printf( "X: %d\n", x );
}
}

void main()
{
Sub ob;
ob.Write();
}

The issue I have is that the Sub class is allowed to access private variables from the base class.  I also noted that this reverts to the correct behavior when these classes are separated into different module files.  Thank you.

---------------
Adam Juersivich
November 14, 2005
lp_fury@hotmail.com wrote:
> I hope this is the proper place to post this.  I noticed that the compiler ran
> fine with this bit of code.
> 
> import std.c.stdio;
> 
> class Base
> {
> private:
> int x;
> }
> 
> class Sub: Base
> {
> public:
> void Write()
> {
> printf( "X: %d\n", x );
> }
> }
> 
> void main()
> {
> Sub ob;
> ob.Write();
> }
> 
> The issue I have is that the Sub class is allowed to access private variables
> from the base class.  I also noted that this reverts to the correct behavior
> when these classes are separated into different module files.  Thank you.
> 
> ---------------
> Adam Juersivich

This is correct behavior - classes in the same module are implicitely each other's "friends" (see c++, friend keyword). I think this detail can be found in the D language manual. However, currently there's a bug in the currect module member access implementation. See the d.bugs newsgroup for details.