template error instantiating
David Nadlinger
see at klickverbot.at
Sat Nov 17 14:05:56 PST 2012
On Saturday, 17 November 2012 at 18:28:10 UTC, 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.
Template functions are currently not overloadable with
non-template ones. As a workaround (if foo(TStuff) doesn't need
to be virtual), you can turn it into a template function (without
parameters, i.e. foo()(TStuff item)) as well.
David
More information about the Digitalmars-d-learn
mailing list