C# style generic interfaces with templates
Robby
robby.lansaw at gmail.com
Sun Jan 14 23:50:15 PST 2007
Newish to D, so bare with me~
I have a few questions surrounding Class Templates and the like if
anyone has time.
After reading the two pages on templates (lex, and revisited) I haven't
seen anything regarding interfaces being templated like classes. However
it doesn't produce a lexical error :
public interface H(T){
T another();
}
public class A(T) : H!(T)
{
T t;
T another(){return t;}
void curious(){}
}
What I'm aiming for is an equivalent to c#'s generic interfaces. So I
can remove casting on my interface declarations.
However, when I do this :
alias A!(int) a;
assert(a.another()==0);
I get the following error : Error: need 'this' to access member another.
So, is there a way where I can template interfaces as I do classes to
give a per type based interfaces to the classes?
Further on...
How do I get the A class instantiated? Is that possible with templated
classes?
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?
Am I wrong to think that I can use and approach class templates as if
I were using generics in c#?
Or am I going about it the wrong way?
More information about the Digitalmars-d-learn
mailing list