C# style generic interfaces with templates

Bradley Smith digitalmars-com at baysmith.com
Sun Jan 14 22:26:43 PST 2007


You almost had it right, but made a couple of minor coding mistakes.

> public interface H(T){
>    T another();
> }
> public class A(T) : H!(T)
> {
>    T t;
>    T another(){return t;}
>    void curious(){}
> }
> 
>  alias A!(int) a;
>  assert(a.another()==0);

In this code, "a" is a type not an object. I changed it to:
   alias A!(int) a;
   a aObject = new a;
   assert(aObject.another()==0);

> public class A(T)
> {
>     T t;
>        this(){}
> }
> 
>  alias A!(int) a;
>  a b = new a(); // doesn't work
>  A! b = new A!(int)();// doesnt either?

The last line is incorrect. I changed it to:
   A!(int) b2 = new A!(int)();

Hope that helps.

   Bradley


More information about the Digitalmars-d-learn mailing list