Class Tempates
Kyle Furlong
kylefurlong at gmail.com
Sun Apr 2 15:26:27 PDT 2006
Frank Benoit wrote:
> 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;
Wait, does this work now? I though we didn't have stack based classes yet.
> 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