title: Counting created objects over 2 different classes leads to problems
body: <p>I want to count created objects. If I do this with one class it is easy, but I want count objects from 2 different classes with 2 different counters interacting with each other.
  Simplified example:</p>
  
  <pre><code>template &lt;class Obj&gt;
  class Counter1
  {
      private: 
          static int total1;
      public:
          Counter1(){++total1;}
          .. destuctor, copy constructor ..
         static int getCounter1() {return total1;}
         static void setCounter1(int var) {total1 = var;}
  };
  template&lt;class Obj&gt; int Counter1&lt;Obj&gt;::total1(0);
  
  template &lt;class Obj&gt;
  class Counter2
  {
      private: 
          static int total2;
      public:
          Counter2(){++total2;}
          .. destuctor, copy constructor ..
         static int getCounter2() {return total2;}
         static void setCounter2(int var) {total2 = var;}
  };
  template&lt;class Obj&gt; int Counter2&lt;Obj&gt;::total2(0);
  
  class Test1 : private Counter1&lt;Test1&gt;
  {
   .. some code ..
  };
  Test1::Test1() : Counter1()
  {
     int tmp_var;
     tmp_var = Counter2&lt;int&gt;::getCounter2();
  }
  </code></pre>
  
  <p>Sadly <code>tmp_var</code> never gets a valid number. Or in other words, it stays at zero and doesn't increase. What am I doing wrong? </p>
  
  <p>_________________EDIT__________________ <br>
  Here a more detailed example as requested:</p>
  
  <pre><code>template &lt;class Obj&gt;
  class Counter1
  {
      private:
          static int total1;
  
      public:
          Counter1() {++total1;}
          Counter1(const Counter1&amp; countObj) {if(this != &amp;countObj) {++total1;}}
          ~Counter1() {--total1;}
  
          static int getCounter1() {return total1;}
          static void setCounter1(int var){total1 = var;}
  };
  template &lt;class Obj&gt; int Counter1&lt;Obj&gt;::total1(0);
  
  template &lt;class Obj&gt;
  class Counter2
  {
      private:
          static int total2;
  
      public:
          Counter2() {++total2;}
          Counter2(const Counter2&amp; countObj) {if(this != &amp;countObj) {++total2;}}
          ~Counter2() {--total2;}
  
          static int getCounter2() {return total2;}
          static void setCounter2(int var){total2 = var;}
  };
  template &lt;class Obj&gt; int Counter2&lt;Obj&gt;::total2(0);
  
  /* Memory are with a static Size with variable object Size allocator */
  class Class1 : private Counter2&lt;Class1&gt;
  {
      public:
          Class1();
  
          .. some methods ..
  
      private:
         .. some members ..
      };
  
  /* Constructor */
  Class1::Class1() : Counter2()
  {
      const int varTotal1 = Counter1&lt;int&gt;::getCounter1();
      const int varTotal2 = getCounter2()-1;
  
      .. some code ..
  }
  
  .. some methods ..
  
  class Class2 : private Counter1&lt;Class2&gt;
  {
      public:
          Class1 _PoolsObj[TASKS_PER_PROCESS];
  
          Class2();
  };
  
  Class2::Class2() : Counter1()
  {
      _PoolsObj[TASKS_PER_PROCESS] = {};
  
      /* Reset the task counter */
      Counter2&lt;int&gt;::setCounter2(0);
  }
  
  static Class2 class_pool[64];
  </code></pre>
  
  <p>I have two problems: 
  <br> 1) <code>Counter2&lt;int&gt;::setCounter2(0);</code> doesn't work
  <br> 2) <code>const int varTotal1 = Counter1&lt;int&gt;::getCounter1();</code> Is always 0</p>