c++ - what is wrong with the template function parameter -
hi new templates. want know how compile programme correctly.
template<class t> class node{ public: t val; node(t v):val(v){} }; template<class t> class stack{ private: stack *next; static stack *head; static int top; public: void push(node *n); node* pop(); }; template<class t> int stack<t>::top=0; template<class t> stack<t>* stack<t>::head=null; template<class t> void stack<t>::push(node<t>* n) //error force function not defined { } int main(int argc, char *argv[]) { node<int> n1(5); homecoming 0; }
the programme gives error
stack<t>::push' : redefinition; different basic types nw.cpp(14) : see declaration of 'stack<t>::push'
thanks in advance
the declaration:
void push(node *n);
should be:
void push(node<t> *n);
c++ templates
No comments:
Post a Comment