www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - bug?

reply bobef <adas adasd.asdasd> writes:
a.d 
-------------------------

import b;

class A
{

private:
	int a;
protected:
	int aa;
}

class B : A
{
	void fff(){a=5;aa=5;}
}

class D : C
{
	void fff(){a=5;}
}

void main()
{
	auto a=new A;
	a.a=5;
	a.aa=5;
}




b.d
----------------------------------------------------

class C
{
	private:
	int a;
}







dmd a b

a.d(20): class a.D member a is not accessible



------------

What the? Not accessible for the child class but accessible for other
classes/functions in the same module?
Apr 05 2007
parent BCS <BCS pathlink.com> writes:
bobef wrote:
 a.d -------------------------
 import b;
[...]
 
 class D : C
 {
 	void fff(){a=5;}
 }
 
[...]
 b.d ----------------------------------------------------
 class C
 {
 	private:
 	int a;
 }
 
 What the? Not accessible for the child class but accessible for other
classes/functions in the same module?
private is "private to this module". In C++ terms (if I remember c++ correctly), everything in a given module has friend access to everything else. The assumption seems to be that if it is in the same module, then encapsulation isn't really that useful. If more separation than that is needed, then the parts should probably be in different modules anyway.
Apr 05 2007