Differing implementations for a function in two interfaces

Lionello Lunesu lio at lunesu.remove.com
Mon Apr 17 23:11:54 PDT 2006


Chris Nicholson-Sauls wrote:
> 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?
> 
> # class Foo : IA, IB { ... } // IA and IB declare: int get();
> #
> # Foo obj = new Foo;
> #
> # // call IA.get()... ew
> # (cast(IA) obj).get();
> #
> # // call IB.get()... eh
> # obj.get at IB();
> # // or
> # obj at IB.get();
> #
> # // call IA.get()... erm
> # obj.IA::get();
> 
> Just thinking.
> 
> -- Chris Nicholson-Sauls

Even when calling, I'd pick the "IB.get" syntax:

#class C : IA, IB {
#  int IA.get() {..}
#  int IB.get() {..}
#}

#void main() {
#  C c = new C;
#//  c.get();//error, ambiguity
#  c.IA.get();//OK, calls IA.get
#  c.IB.get();//OK, calls IB.get
#}

But there's probably some syntax parsing problem I know nothing about.

L.



More information about the Digitalmars-d-learn mailing list