title: C++ Class Method Inheritance
body: <p>I have recently transitioned from Java to C++, and I am having some difficulties working out how class inheritance works exactly. Currently, I have the class <code>Weapon</code> and the class <code>Minigun</code>. <code>Minigun</code> inherits the class <code>Weapon</code>, which means it should have the methods and variables that <code>Weapon</code> defines. My issue is that I have a private constant static int inside <code>Weapon</code> called <code>rate</code>, and a public method that returns an integer called <code>getRate()</code>. <code>getRate()</code> simply returns the rate variable as defined in the class. When <code>Minigun</code> extends <code>Weapon</code>, and I set the rate inside <code>Minigun</code>, the <code>getRate()</code> method still returns the constant from the <code>Weapon</code> class, even though it is being called on the <code>Minigun</code> class. I thought it would act like Java, and the intherited method would use the modified variable inside <code>Minigun</code>. Currently I have to do the following;</p>
  
  <p><strong>Weapon.h</strong></p>
  
  <pre><code>#ifndef __WEAPON__
  #define __WEAPON__
  
  class Weapon
  {
      public:
          virtual int getRate()
          {
              return rate;
          }
      private:
          const static int rate = 0;
  };
  
  #endif
  </code></pre>
  
  <p><strong>Minigun.h</strong></p>
  
  <pre><code>#include "Weapon.h"
  
  #ifndef __WEAPON_MINIGUN__
  #define __WEAPON_MINIGUN__
  
  class Minigun: public Weapon
  {
  public:
      int getRate(); // I have to define this here, and create it inside Minigun.cpp
  private:
      const static int rate = 30;
  };
  
  #endif
  </code></pre>
  
  <p><strong>Minigun.cpp</strong></p>
  
  <pre><code>#include "Minigun.h"
  
  int Minigun::getRate() // Is there a way so I do not need to type this out for every class that extends Weapon?
  {
      return rate;
  }
  </code></pre>