interface function overloading
Jonathan M Davis
jmdavisProg at gmx.com
Sat Jan 8 22:04:15 PST 2011
On Saturday 08 January 2011 22:01:11 %u wrote:
> Isn't it possible to have a hierarchy in interface definitions such that it
> is possible to overload according to best interface match?
>
> This now won't compile due to multiple matches.
>
> ----
> module main;
>
> interface I1{}
> interface I2 : I1{}
>
> class C : I2{
> this(){}
> }
>
> void func(I1 i){}
> void func(I2 i){}
>
> void main(){
> func(new C());
> }
> ----
Very little - if anything - in the way of overloading in D works by "best
match." It pretty much always has to be exact or implicitly convertible and be
the _only_ option which is implicitly convertible. Sometimes, it can be pretty
annoying, but it's done to avoid cases where you accidentally call one function
when you mean another, like you can get in C++ fairly easily.
Take a look at http://www.digitalmars.com/d/2.0/hijack.html
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list