Static class member declaration error
<p>I am trying to find dynamically and statically instantiated objects number.  I am getting errors that variable myheap is not declared.</p>

<pre><code>#include&lt;iostream.h&gt;
#include&lt;stdlib.h&gt;

class A {
public:
  static int x;   //To count number of total objects. incremented in constructor
  static int myheap;  //To count number of heap objects. Incremented in overloaded new

  void* operator new(size_t t) {
    A *p;
    p=(A*)malloc(t);
    myheap++;
    return p;
  }

  void operator delete(void *p) {
    free(p);
    myheap--;
  }

  A() {
    x++;
  }

  ~A() {
    x--;
  }
};
int A::x=0;
int A::myheap=0;

int main() {
  A *g,*h,*i;
  A a,c,b,d,e;//Static allocations 5

  g= new A();//Dynamic allocations 3
  h= new A();
  i= new A();

  cout&lt;&lt;"Total"&lt;&lt;A::x&lt;&lt;'\n';

  cout&lt;&lt;"Dynamic";
  cout&lt;&lt;'\n'&lt;&lt;"HEAP"&lt;&lt;A::myheap;

  delete g;
  cout&lt;&lt;'\n'&lt;&lt;"After delete g"&lt;&lt;A::x;
  cout&lt;&lt;'\n'&lt;&lt;"HEAP"&lt;&lt;A::myheap;
  delete h;
  cout&lt;&lt;'\n'&lt;&lt;"After delete h"&lt;&lt;A::x;
  cout&lt;&lt;'\n'&lt;&lt;"HEAP"&lt;&lt;A::myheap;
  delete i;
  cout&lt;&lt;'\n'&lt;&lt;"After delete i"&lt;&lt;A::x;
  cout&lt;&lt;'\n'&lt;&lt;"HEAP"&lt;&lt;A::myheap;
}
</code></pre>
