Created
October 17, 2020 13:52
-
-
Save sidewinder040/9c127bda854652eb423a0a8ae73d658b to your computer and use it in GitHub Desktop.
C++ Static Vector Class
This file contains hidden or 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> | |
#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