Differing implementations for a function in two interfaces
BCS
BCS_member at pathlink.com
Sat Apr 15 10:55:43 PDT 2006
In article <e1qgma$1ngm$1 at digitaldaemon.com>, Chris Nicholson-Sauls says...
>
>Lionello Lunesu wrote:
>> #class Command : IResult, IResultRow { // handle wrapper
>...
>> # int IResult.opApply( int delegate(inout IResultRow) dg );
>...
>> # int IResultRow.opApply( int delegate(inout IResultField) dg );
>> #}
>
>I actually rather like this syntax. When I first started reading your post, this was
>precisely what I thought of as a possible general purpose solution. The difficulty I see
>is in how to select which to use at call-time. In your case, I see you use a simple
>`cast(Interface) object` to do so, which seems fair enough... but might there be another
>way to do the selection in simpler expressions?
>
Its not to clean but the use of aliases could be a solution to this and other
problems, namely, now dose a class implement an interface with inherited
functions?
Interface thingI
{
char[] getName()
char[] getType()
}
Class foo
{
char[] name(){...}
//no type
}
class bar : thingI
{
char[] type(){...}
alias name : thingI.getName; //need not have the same name
alias type : thingI.getTypr;
}
but this would require that bug #52 be fixed so that DMD can distinguish between
overloaded function
e.g.
int foo(int i){...}
int foo(char c){...}
auto fnp = &foo; // what type is fnp? DMD makes an arbitrary selection that is
context dependent.
More information about the Digitalmars-d-learn
mailing list