template error instantiating

Timon Gehr timon.gehr at gmx.ch
Sat Nov 17 14:34:43 PST 2012


On 11/17/2012 07:28 PM, ref2401 wrote:
> I get "template instance main.MyClass!(int) error instantiating" in the
> following case:
>
> public class MyClass(TStuff)
> {
>      public void foo(TStuff item)
>      {}
>
>      public void foo(TRange)(TRange items)
>      if (isInputRange!TRange && is(ElementType!TRange == TStuff))
>      {}
> }
>
> void main(string[] argv)
> {
>      MyClass!int instance = new MyClass!int();
>
>      return;
> }
>
> but if i rename one of the "foo" overloads then code will be compiled.
>

Making the first overload a template fixes your issue, but note that 
your code is indeed valid D code. It is the compiler which does not 
implement overloading of functions vs. function templates yet.


More information about the Digitalmars-d-learn mailing list