Skip to content

Instantly share code, notes, and snippets.

@steveobbayi
Created March 31, 2016 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveobbayi/b28c34bc46415888a8b4fa565baa851e to your computer and use it in GitHub Desktop.
Save steveobbayi/b28c34bc46415888a8b4fa565baa851e to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
template <typename T> // remember this line makes the class a template
class MyVector{
T a[10];
int count;
public:
MyVector():count(0){}
void push[T x]{ a[count] = x; count++;}
void print const {for(int i=0; i<count; i++){
cout << a[i] << endl;}}
};
int main(){
MyVector<int> v; // explicitly specify the int in angle brackets
v.push(4);
v.push(8);
v.push(7);
v.push(3);
v.push(9);
v.push(1);
v.print(); //returns 4 8 7 3 9 1 ... each number of course on a new line
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment