Skip to content

Instantly share code, notes, and snippets.

@sidewinder040
Created October 17, 2020 13:52
Show Gist options
  • Save sidewinder040/9c127bda854652eb423a0a8ae73d658b to your computer and use it in GitHub Desktop.
Save sidewinder040/9c127bda854652eb423a0a8ae73d658b to your computer and use it in GitHub Desktop.
C++ Static Vector Class
#include <iostream>
#include <vector>
using namespace std;
class List
{
private:
static vector<int> Numbers;
public:
List();
static void AddNumber(int num);
static void ListNumbers();
};
void List::AddNumber(int num) {
Numbers.push_back(num);
}
List::List() {
}
vector<int> List::Numbers;
void List::ListNumbers() {
for(auto i : Numbers) {
cout << "Number: " << i << endl;
}
}
int main(int argc, char const *argv[])
{
List::AddNumber(2);
List::AddNumber(10);
List::AddNumber(8);
List::ListNumbers();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment