auto attribute for interface functions
Roman
shamyan.roman at gmail.com
Tue Oct 8 08:26:04 PDT 2013
On Tuesday, 8 October 2013 at 13:40:47 UTC, Roman wrote:
> ```
> 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 ?
Seems, I've tried to use virtual templates manner. But it doesn't
realizes in D yet
More information about the Digitalmars-d-learn
mailing list