opCall and template functions

Steve Teale steve.teale at britseyeview.com
Thu May 21 07:01:44 PDT 2009


Is this error intentional

import std.stdio;

class A
{
   int a;
   double b = 22.4;
   string s = "whatever";

   string opCall() { return s; }
   //T opCall(T = string)() { return cast(T) s; }

   T opCall(T)(T* dummy)
   {
      if (is(typeof(dummy) : int*))
         return cast(T) a;
      else
         return cast(T) b;
   }
}

double* D;
int* I;

void main()
{
   A a = new A();
   double d = a(D);
   writefln("d = %f", d);

   int n = a(I);
   writefln("n = %d", n);

   writefln(a());
}

strange.d(10): Error: template strange.A.opCall(T) conflicts with function strange.A.opCall at strange.d(8)

You can make it work with the template version of opCall with no args




More information about the Digitalmars-d mailing list