access member error

Jonathan M Davis jmdavisprog at gmail.com
Fri Sep 3 02:13:31 PDT 2010


On Friday 03 September 2010 00:36:11 existen wrote:
> I've got 2 classes:
> 
> class A {
> 	private int _x = 5;
> }
> 
> class B : A {
> 	void output() {
> 		writeln(_x);
> 	}
> }
> 
> When I call
> (new B).output()
> there is no compile-time or run-time errors. Is it correct?

This is the wrong list to send posts to. All of the posts here come from the bug 
tracker. Use digitalmars-d-learn for questions about how D works or how to do 
things in D.

As for your code, it looks just fine to me assuming that A and B are in the same 
module. private is private to the module, not the class. If A and B are in 
separate modules, then B would not have access to _x, and it wouldn't work. For 
that to work, you'd need to make _x protected. But if they're in the same 
module, then it should work just fine.

- Jonathan M Davis


More information about the Digitalmars-d-bugs mailing list