auto attribute for interface functions

Roman shamyan.roman at gmail.com
Tue Oct 8 06:40:45 PDT 2013


```
interface I
{
	//auto foo(int i); //forbidden

	auto bar(T)(T i); //Error: function a.I.bar!(int).bar has no 
function body with return type inference
}

class A:I
{
	int foo(int i)
	{
		return i;
	}

	T bar(T)(T i)
	{
		return i;
	}
}

class B:I
{
	int foo(int i)
	{
		return i;
	}

	string bar(T)(T i)
	{
		import std.conv;
		return to!string(i);
	}
}

void main()
{
	import std.stdio;

	//void fun(I i)
	//{
	//	writeln(i.bar(1)); //Error (see above)
	//}

	auto a = new A();
	auto b = new B();

	writeln(a.foo(2)); //works fine
	writeln(a.foo(3)); //works fine

	//fun(a); //Error (see above)
	//fun(b); //Error (see above)
}
```
Does class A or class B implement I ?


More information about the Digitalmars-d-learn mailing list