sequence template : template class « Class « C++

sequence template

#include <iostream>
using namespace std;

template <class T, int N>
class sequence {
    T memblock [N];
    void setmember (int x, T value);
    T getmember (int x);

template <class T, int N>
void sequence<T,N>::setmember (int x, T value) {

template <class T, int N>
T sequence<T,N>::getmember (int x) {
  return memblock[x];

int main () {
  sequence <int,5> myints;
  sequence <double,5> myfloats;
  myints.setmember (0,100);
  myfloats.setmember (3,3.1416);
  cout << myints.getmember(0) << '\n';
  cout << myfloats.getmember(3) << '\n';
  return 0;

Related examples in the same category

1.template class with type parameter
2.template class with generic parameter
3.Demonstrate a very simple safe pointer class.
4.A generic safe-array class that prevents array boundary errors.
5.Get storage off stack for array
6.template extending
7.Template Version of Generic binary sorted Tree.
8.template class with two generic parameters
9.generic stack template class
10.Using exceptions with templates.
11.Passing by reference and using virtual functions in exceptions.
12.Using Non-Type Arguments with Generic Classes
13.Using Default Arguments with Template Classes
14.Generic Classes: demonstrates a generic stack.
15.An Example with Two Generic Data Types
16.Applying Template Classes: A Generic Array Class
17.Explicit Class Specializations for generic template class