I\'d like to be able to count instances of classes that belong in the same class hierarchy.
For example, let\'s say I have this:
class A;
class B: pu
Use a static
member variable for each class.
struct A {
A() { mInstances++; }
~A() { mInstances--; }
static size_t mInstances;
static size_t GetInstancesCount() { return mInstances; }
};
size_t A::mInstances;
int main() {
A* a = new A;
A* aa = new A;
cout << A::GetInstancesCount() << endl;
delete a;
delete aa;
cout << A::GetInstancesCount() << endl;
return 0;
}