In creating a templated class, it is probably easier to create a specific class and then turn it into a templated class.
// class myqueue.h class myqueue { public: myqueue( ); ~myqueue( ); myqueue (const myqueue &R); const int front( ) const; bool isEmpty( ) const; int length( ) const; void enqueue(int item ); ... private: struct nodetype { int info; nodetype * next; nodetype (int &D, nodetype *N) : info(D), next(N) { } }; ... |
// class myqueue.h - a templated class template <class someType> class myqueue { public: myqueue( ); ~myqueue( ); myqueue (const myqueue &R); const someType front( ) const; bool isEmpty( ) const; int length( ) const; void enqueue(const someType & item ); ... private: struct nodetype { someType info; nodetype * next; nodetype (someType & D, nodetype * N) : info (D), next (N) { } }; ... |
// myqueue.cpp myqueue::myqueue( ) { mySize = 0; myfront = NULL; myback = NULL; } myqueue::~myqueue( ) { makeEmpty( ); } ... const int myqueue::front( ) { return (myfront->info); ... } void myqueue::dequeue(int &item) { item = myfront->info; ... { |
// myqueue.cpp template <class someType> myqueue<someType> ::myqueue( ) { mySize = 0; myfront = NULL; myback = NULL; } template <class someType> myqueue<someType>::~myqueue( ) { makeEmpty( ); } ... template <class someType> const someTypemyqueue<someType> ::front( ) const; { return (myfront->info); ... } template <class someType> void myqueue<someType> ::dequeue(someType & item) { item = myfront->info; ... } |