C# style generic interfaces with templates

Robby robby.lansaw at gmail.com
Mon Jan 15 15:09:52 PST 2007


Sweet!, now I can port my collection classes to d without casting hell, 
thanks!

Robby

Bradley Smith wrote:
> 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