Class Tempates
Frank Benoit
benoit__ at __tionex.de
Sun Apr 2 09:11:46 PDT 2006
Ark schrieb:
> Hello Frank,
>
> It works !
>
> I realize now that i missed two points :
> First i used template Stack (T) instead of class Stack(T)
> Second i missed the auto keyword...
>
> Thanks.
>
>
You can also write this without auto and with template:
template(T)
{
class Stack
{
public:
this() {
top = -1;
}
void push(T i){
st[++top] = i;
}
T pop(){
return st[top--];
}
private:
int top;
T[100] st;
}
}
int main ( char[][] args)
{
alias Stack!(int) StackI;
alias Stack!(char[]) StackS;
StackI ii = new StackI;
StackS ss = StackS;
ii.push(25);
ss.push("Hello");
return 0;
}
For more information see:
http://www.digitalmars.com/d/template.html
More information about the Digitalmars-d
mailing list