Differing implementations for a function in two interfaces

Lionello Lunesu lio at lunesu.remove.com
Sun Apr 16 23:14:47 PDT 2006


Ryan Steen wrote:
> In article <e1qem7$1lvs$1 at digitaldaemon.com>, Lionello Lunesu says...
> 
>> #class Command : IResult, IResultRow {	// handle wrapper
>> #	sqlite3_stmt* stmt;
>> #	~this() { sqlite3_finalize(stmt); }
>> #	IResult Execute() { return cast(IResult)this; }
>> #	// this one iterates rows; does cast(IResultRow)this
>> #	int IResult.opApply( int delegate(inout IResultRow) dg );
>> #	// this one iterates fields; does new ResultField(this,fieldno)
>> #	int IResultRow.opApply( int delegate(inout IResultField) dg );
>> #}
> 
> I do not see the problem here because the opApply from the different interfaces
> do not have identical formal parameter lists. Therefore your code above is very
> vlose to the solution:
> 
> #class Command : IResult, IResultRow {	// handle wrapper
> #	sqlite3_stmt* stmt;
> #	~this() { sqlite3_finalize(stmt); }
> #	IResult Execute() { return this; }
> #	// this one iterates rows; does cast(IResultRow)this
> #	int opApply( int delegate(inout IResultRow) dg );
> #	// this one iterates fields; does new ResultField(this,fieldno)
> #	int opApply( int delegate(inout IResultField) dg );
> #}

Brilliant!!! Why didn't I think of that.. Indeed, it works. BUT, I could 
not provide the opIndex and opCall operators:

#class Parameter {..}

#class Command {
#  // return command parameter i
#  Parameter opIndex(uint i);
#  // return command parameter named n
#  Parameter opCall(char[] n);
#}

#class ResultRow {
#  // return field at index i
#  ResultField opIndex(uint i);
#  // return field named n
#  ResultField opCall(char[] n);
#}

So the problem in the original post still applies to opIndex and opCall.

Thanks a lot for the suggestion ;)

L.



More information about the Digitalmars-d-learn mailing list