Thread overview
Multiple opCall's
Feb 21, 2011
useo
Feb 21, 2011
Mafi
Feb 21, 2011
useo
Feb 21, 2011
Jonathan M Davis
February 21, 2011
Hey guys,

I've a small problem implementing multiple opCall()-methods. At first, I've the following interface:

interface Invoker {
 void opCall(uint i);
}

... and an abstract class which inherits from the Invoker-interface like the following:

abstract class AbstractInvoker : Invoker {

 private int myInt;

 override void opCall(uint i) { /** do nothing */ }

 void opCall() {
  opCall(myInt);
 }

}

I know... I can remove the opCall(uint i) from the interface, but it's needed for some other classes which implements this method. For
those classes the opCall(uint i)-method is needed.

But... when I now declare a class like this:

class InvokableClass : AbstractInvoker {
 override void opCall(uint i) {
  // do something
 }
}

and do the following:

void main(string[] args) {
 InvokableClass() ic = new InvokeableClass();
 ic();
}

I always get the following errors:

Error: function InvokableClass.opCall (uint i) is not callable using argument types ().
Error: expected 1 function arguments, not 0

But I think opCall() is implemented in the abstract class and should be callable using opCall() instead using opCall(uint i)?
February 21, 2011
Am 21.02.2011 11:18, schrieb useo:
> Hey guys,
>
> I've a small problem implementing multiple opCall()-methods. At first, I've the following interface:
>
> interface Invoker {
>   void opCall(uint i);
> }
>
> ... and an abstract class which inherits from the Invoker-interface like the following:
>
> abstract class AbstractInvoker : Invoker {
>
>   private int myInt;
>
>   override void opCall(uint i) { /** do nothing */ }

In an abstract class you can just leave this out. The inheriting class will then be checked to implement this.

>
>   void opCall() {
>    opCall(myInt);
>   }
>
> }
>
> I know... I can remove the opCall(uint i) from the interface, but it's needed for some other classes which implements this method. For
> those classes the opCall(uint i)-method is needed.
>
> But... when I now declare a class like this:
>
> class InvokableClass : AbstractInvoker {
>   override void opCall(uint i) {
>    // do something
>   }
> }
>
> and do the following:
>
> void main(string[] args) {
>   InvokableClass() ic = new InvokeableClass();
>   ic();
> }
>
> I always get the following errors:
>
> Error: function InvokableClass.opCall (uint i) is not callable using argument types ().
> Error: expected 1 function arguments, not 0
>
> But I think opCall() is implemented in the abstract class and should be callable using opCall() instead using opCall(uint i)?

Overriding one opCall shadows all other opCalls inherited from the base class. This behaviour is like with any method. Write:

override void opCall() {
	super.opCall();
}

to forward to the base class method.
AFAIK it's an anti-hijacking machanism.
February 21, 2011
== Auszug aus Mafi (mafi@example.org)'s Artikel
> Am 21.02.2011 11:18, schrieb useo:
> > Hey guys,
> >
> > I've a small problem implementing multiple opCall()-methods. At
first, I've the following interface:
> >
> > interface Invoker {
> >   void opCall(uint i);
> > }
> >
> > ... and an abstract class which inherits from the Invoker-
interface like the following:
> >
> > abstract class AbstractInvoker : Invoker {
> >
> >   private int myInt;
> >
> >   override void opCall(uint i) { /** do nothing */ }
> In an abstract class you can just leave this out. The inheriting
class
> will then be checked to implement this.
> >
> >   void opCall() {
> >    opCall(myInt);
> >   }
> >
> > }
> >
> > I know... I can remove the opCall(uint i) from the interface, but
it's needed for some other classes which implements this method. For
> > those classes the opCall(uint i)-method is needed.
> >
> > But... when I now declare a class like this:
> >
> > class InvokableClass : AbstractInvoker {
> >   override void opCall(uint i) {
> >    // do something
> >   }
> > }
> >
> > and do the following:
> >
> > void main(string[] args) {
> >   InvokableClass() ic = new InvokeableClass();
> >   ic();
> > }
> >
> > I always get the following errors:
> >
> > Error: function InvokableClass.opCall (uint i) is not callable
using argument types ().
> > Error: expected 1 function arguments, not 0
> >
> > But I think opCall() is implemented in the abstract class and
should be callable using opCall() instead using opCall(uint i)?
> Overriding one opCall shadows all other opCalls inherited from the
base
> class. This behaviour is like with any method. Write:
> override void opCall() {
> 	super.opCall();
> }
> to forward to the base class method.
> AFAIK it's an anti-hijacking machanism.

Okay, thanks... this helped a lot!
February 21, 2011
On Monday 21 February 2011 02:47:03 Mafi wrote:
> Am 21.02.2011 11:18, schrieb useo:
> > Hey guys,
> > 
> > I've a small problem implementing multiple opCall()-methods. At first,
> > I've the following interface:
> > 
> > interface Invoker {
> > 
> >   void opCall(uint i);
> > 
> > }
> > 
> > ... and an abstract class which inherits from the Invoker-interface like the following:
> > 
> > abstract class AbstractInvoker : Invoker {
> > 
> >   private int myInt;
> > 
> >   override void opCall(uint i) { /** do nothing */ }
> 
> In an abstract class you can just leave this out. The inheriting class will then be checked to implement this.
> 
> >   void opCall() {
> > 
> >    opCall(myInt);
> > 
> >   }
> > 
> > }
> > 
> > I know... I can remove the opCall(uint i) from the interface, but it's
> > needed for some other classes which implements this method. For those
> > classes the opCall(uint i)-method is needed.
> > 
> > But... when I now declare a class like this:
> > 
> > class InvokableClass : AbstractInvoker {
> > 
> >   override void opCall(uint i) {
> > 
> >    // do something
> > 
> >   }
> > 
> > }
> > 
> > and do the following:
> > 
> > void main(string[] args) {
> > 
> >   InvokableClass() ic = new InvokeableClass();
> >   ic();
> > 
> > }
> > 
> > I always get the following errors:
> > 
> > Error: function InvokableClass.opCall (uint i) is not callable using
> > argument types (). Error: expected 1 function arguments, not 0
> > 
> > But I think opCall() is implemented in the abstract class and should be
> > callable using opCall() instead using opCall(uint i)?
> 
> Overriding one opCall shadows all other opCalls inherited from the base class. This behaviour is like with any method. Write:
> 
> override void opCall() {
> 	super.opCall();
> }
> 
> to forward to the base class method.
> AFAIK it's an anti-hijacking machanism.

Or you can use alias. Inside of Invokable class, put

alias AbstractInvokableClass.opCall opCall;

That should put all of AbstractInvokableClass' in the overload set for InvokableClass.

- Jonathan M Davis