digitalmars.D.learn - Method of another module is callable, even if they is private.
- Namespace (39/39) Oct 12 2013 A.d:
- Andrej Mitrovic (21/22) Oct 12 2013 Has to be a bug. Reduced:
- Namespace (5/27) Oct 12 2013 Ok, I've opened a bug report for this.
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
Oct 12 2013
On 10/12/13, Namespace <rswhite4 googlemail.com> wrote:Bug or feature? :PHas to be a bug. Reduced: ----- module a; import b; void main() { auto s = S(); auto f = &s.f; // no error f(); // no error auto sf = &S.sf; // error } ----- ----- module b; struct S { private void f() { } private static void sf() { } } -----
Oct 12 2013
On Saturday, 12 October 2013 at 19:07:44 UTC, Andrej Mitrovic wrote:On 10/12/13, Namespace <rswhite4 googlemail.com> wrote:Ok, I've opened a bug report for this. Otherwise it would be a nice C++-friend like feature. :D Of course, a bit protection would be needed.Bug or feature? :PHas to be a bug. Reduced: ----- module a; import b; void main() { auto s = S(); auto f = &s.f; // no error f(); // no error auto sf = &S.sf; // error } ----- ----- module b; struct S { private void f() { } private static void sf() { } } -----
Oct 12 2013