Created
March 31, 2016 16:41
-
-
Save steveobbayi/b28c34bc46415888a8b4fa565baa851e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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