Method of another module is callable, even if they is private.

Namespace rswhite4 at googlemail.com
Sat Oct 12 11:51:16 PDT 2013


A.d:
----
import B;

class Foo {
public:
	void call(Bar b) {
		b.test(42);
	}
}

void main() {
	Bar b = new Bar();
	Foo f = new Foo();
	f.call(b);
}
----

B.d:
----
import std.stdio;

class Bar {
private:
	void test(int id) {
		writeln("Bar called with ", id);
	}
}
----
As expected:
Output: A.d(6): Error: class B.Bar member test is not accessible

But with this little change of A's Foo class:
----
class Foo {
public:
	void call(Bar b) {
		void delegate(int) dg = &b.test;
		dg(42);
	}
}
----

It works: Bar.bar with 42

Bug or feature? :P


More information about the Digitalmars-d-learn mailing list