Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Malliluokan esittely

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 StackTemplaten eli  mallin esittely näyttää tavallisen luokan esittelyltä paitsi, että siinä on sana template. Seuraavassa on malli pinolle.

Code Block
template <class T>

class Stack
{
  public:
  Stack(int = 10) ;
  ~Stack() { delete [] stackPtr ; }
  int push(const T&);
  int pop(T&) ;
  int isEmpty()const { return top == -1 ; }
  int isFull() const { return top == size - 1 ; }
private:
  int size ;  // elementtien määrä pinossa
  int top ;
  T* stackPtr ;
} ;