You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Class Templates

Implementing a class template

A class template definition looks like a regular class definition, except it is prefixed by the keyword template. For example, here is the definition of a class template for a Stack.template &ltclass T>
class Stack
{
public:
Stack(int = 10) ;
~Stack()

Unknown macro: { delete [] stackPtr ; }

int push(const T&);
int pop(T&) ;
int isEmpty()const

Unknown macro: { return top == -1 ; }

int isFull() const

Unknown macro: { return top == size - 1 ; }

private:
int size ; // number of elements on Stack.
int top ;
T* stackPtr ;
} ;

  • No labels
You must log in to comment.