digitalmars.D.bugs - Private member access
- Russell <Russell_member pathlink.com> May 05 2004
- J Anderson <REMOVEanderson badmama.com.au> May 05 2004
Seems I can access private class members from outside the class?
class Test2
{
private void privateFunct()
{
printf("How can this be?\n");
}
}
int main ( char [] [] args )
{
Test2 t2 = new Test2();
t2.privateFunct();
return 1;
}
This code compiles and runs. Shouldn't this fail compilation?
Russell
May 05 2004
Russell wrote:Seems I can access private class members from outside the class? class Test2 { private void privateFunct() { printf("How can this be?\n"); } } int main ( char [] [] args ) { Test2 t2 = new Test2(); t2.privateFunct(); return 1; } This code compiles and runs. Shouldn't this fail compilation?
ie //file X.d module X; class Test2 { private void privateFunct() { printf("How can this be?\n"); } } //file main import X; int main ( char [] [] args ) { Test2 t2 = new Test2(); t2.privateFunct(); //Compiler Error return 1; } Therefore everything in the same module are friends (to use a C++ term). -- -Anderson: http://badmama.com.au/~anderson/
May 05 2004








J Anderson <REMOVEanderson badmama.com.au>