Created
August 12, 2013 22:52
-
-
Save Mon-Ouie/6216102 to your computer and use it in GitHub Desktop.
This file contains 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> | |
class Test { | |
public: | |
Test() { | |
instance_count++; | |
} | |
static void printCounter() { std::cout << instance_count << std::endl; } | |
private: | |
static int instance_count; | |
}; | |
class SubTest : public Test {}; | |
int Test::instance_count = 0; | |
int main(int argc, char **argv) { | |
Test(); | |
Test(); | |
SubTest(); | |
/* Will print 3 twice */ | |
Test::printCounter(); | |
SubTest::printCounter(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment