www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Compiler Issue when using GDC on Cygwin

reply lp_fury hotmail.com writes:
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
Nov 14 2005
parent =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak invalid_utu.fi> writes:
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.
Nov 14 2005