Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created August 12, 2013 22:52
Show Gist options
  • Save Mon-Ouie/6216102 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/6216102 to your computer and use it in GitHub Desktop.
#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