Which template is recommended.

sclytrack sclytrack at iq87.fr
Sun May 27 02:43:08 PDT 2012


Below there are two routines with the same name.
Apparently both can be present at the same time.

Which one of the two is the recommended code?



import std.stdio;

interface ITest
{
	int first();
	int second();
}

class Test: ITest
{
	int first()
	{
		writeln("first");
		return 1;
	}
	
	int second()
	{
		writeln("second");
		return 2;
	}
}

void routine(T:ITest) (T a)
{
	a.second();	
}

void routine(T) (T a) if (is(T:ITest))
{
	a.first();
}

int main()
{
	routine(new Test());
	return 0;
}


-----------------------
The above example prints out first.


More information about the Digitalmars-d mailing list