Counting instances of individual derived classes
<p>I'd like to be able to count instances of classes that belong in the same class hierarchy.</p>

<p>For example, let's say I have this:</p>

<pre><code>class A;
class B: public A;
class C: public B;
</code></pre>

<p>and then I have this code</p>

<pre><code>A* tempA = new A;
B* tempB = new B;
C* tempC = new C;
C* tempC2 = new C;

printf(tempA-&gt;GetInstancesCount());
printf(tempB-&gt;GetInstancesCount());
printf(tempC-&gt;GetInstancesCount());
</code></pre>

<p>the result of that should print<br>
    1<br>
    1<br>
    2<br></p>

<p>The counting, ideally, should be done internally. Each class, and not some kind of manager, should know how many instances it has.</p>

<p>Any ideas?</p>

<p>Thanks!</p>
