Skip to content

Instantly share code, notes, and snippets.

@acgetchell
Last active December 21, 2015 16:08
Show Gist options
  • Select an option

  • Save acgetchell/6331156 to your computer and use it in GitHub Desktop.

Select an option

Save acgetchell/6331156 to your computer and use it in GitHub Desktop.
Sequence template
//
// main.cpp
// LearningCplusplus
//
// Created by Getchell, Adam on 7/9/13.
// Templating tutorial
// http://www.cplusplus.com/doc/tutorial/templates/
// sequence template
#include <iostream>
#include LearningCplusplusConfig.h;
using namespace std;
template <class T, int N>
class mysequence {
T memblock [N];
public:
void setmember (int x, T value);
T getmember (int x);
};
template <class T, int N>
void mysequence<T,N>::setmember(int x, T value) {
memblock[x]=value;
}
template <class T, int N>
T mysequence<T,N>::getmember (int x) {
return memblock[x];
}
int main() {
mysequence<int,5> myints;
mysequence<double, 5> myfloats;
myints.setmember(0, 100);
myfloats.setmember(3, 3.1416);
cout << myints.getmember(0) << '\n';
cout << myfloats.getmember(3) << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment