We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 15e766c commit a33510fCopy full SHA for a33510f
static_member_variable.cpp
@@ -0,0 +1,27 @@
1
+#include <vector>
2
+#include <string>
3
+#include <iostream>
4
+
5
+//https://www.learncpp.com/cpp-tutorial/static-member-variables/
6
7
+using namespace std;
8
9
+class Visitor {
10
+private:
11
+ static int count; // this only "declares" the variable!
12
13
+public:
14
+ Visitor() { ++count; }
15
+ static int get() { return count; }
16
+};
17
18
+int Visitor::count = 10; // actually "defines" the variable
19
20
+int main(int argc, char** argv) {
21
+ Visitor v1;
22
+ cout << Visitor::get() << endl; // 11
23
+ Visitor v2;
24
+ cout << Visitor::get() << endl; // 12
25
26
+ return 0;
27
+}
0 commit comments