Skip to content

Instantly share code, notes, and snippets.

@illescasDaniel
Created November 26, 2016 15:53
Show Gist options
  • Select an option

  • Save illescasDaniel/48191ba9824898e62b56c1040d35b18a to your computer and use it in GitHub Desktop.

Select an option

Save illescasDaniel/48191ba9824898e62b56c1040d35b18a to your computer and use it in GitHub Desktop.
Static members [C++]
#include <iostream>
using namespace std;
struct Box {
static int objectCount;
static constexpr int test = 20;
Box() {
objectCount++;
}
};
int Box::objectCount = 0; // Initialize static member
int main() {
Box Box1;
cout << Box::objectCount << endl;
cout << Box::test << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment