Thread overview | |||||
---|---|---|---|---|---|
|
April 26, 2014 Another bug in function overloading? | ||||
---|---|---|---|---|
| ||||
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) |
April 26, 2014 Re: Another bug in function overloading? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domain | 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 |
April 26, 2014 Re: Another bug in function overloading? | ||||
---|---|---|---|---|
| ||||
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.. |
Copyright © 1999-2021 by the D Language Foundation