digitalmars.D.learn - Another bug in function overloading?
- Domain (30/30) Apr 25 2014 module test;
- Jonathan M Davis via Digitalmars-d-learn (37/73) Apr 26 2014 On Sat, 26 Apr 2014 06:55:38 +0000
- Andrej Mitrovic via Digitalmars-d-learn (5/6) Apr 26 2014 I wonder whether a better diagnostic could help. But then again, maybe
module test; public interface I { void foo(); void foo(int); } public abstract class A : I { public void bar() { foo(); } public void foo(int i) { } } public class C : A { public void foo() { } public void bar2() { foo(1); } } Error: function test.A.foo (int i) is not callable using argument types () Error: function test.C.foo () is not callable using argument types (int)
Apr 25 2014
On Sat, 26 Apr 2014 06:55:38 +0000 Domain via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:module test; public interface I { void foo(); void foo(int); } public abstract class A : I { public void bar() { foo(); } public void foo(int i) { } } public class C : A { public void foo() { } public void bar2() { foo(1); } } Error: function test.A.foo (int i) is not callable using argument types () Error: function test.C.foo () is not callable using argument types (int)No. That's expected. If you've overloaded a function from a base class, only the functions in the derived class are in the overload set, so you have to bring the base class' overload into the overload by either overriding the base class overload in the derived class or by aliasing it in the derived class. e.g. module test; public interface I { void foo(); void foo(int); } public abstract class A : I { public void bar() { foo(); } alias I.foo foo; public void foo(int i) { } } public class C : A { alias A.foo foo; public void foo() { } public void bar2() { foo(1); } } - Jonathan M Davis
Apr 26 2014
On 4/26/14, Jonathan M Davis via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:No. That's expected.I wonder whether a better diagnostic could help. But then again, maybe the hiding would be intentional and the diagnostic would be spurious/invalid. Not sure..
Apr 26 2014