Created
November 26, 2016 15:53
-
-
Save illescasDaniel/48191ba9824898e62b56c1040d35b18a to your computer and use it in GitHub Desktop.
Static members [C++]
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> | |
| 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