title: How to properly use virtual member functions in c++
body: <p>I am having a problem with the following code, the overriden virtual functions are not executing. Not sure i'm doing wrong here probably a silly mistake. Anyway this is a game project and I have an array of objects which looks like this (the core::array is an irrlicht array, similar to the vector array)</p>
  
  <pre><code>core::array&lt;GameObject&gt; gameTargets;
  </code></pre>
  
  <p>This is the <code>GameObject</code> and <code>Zombie</code>  definition</p>
  
  <pre><code>class GameObject {
  protected:
      scene::ISceneNode* node;
  public:
      int ID;
      int hitpoints;
  
      GameObject() {
          ...
      };
  
      void setNode(scene::ISceneNode* inode) {
          ...
      }
  
      virtual void shot(int dmg) {
          ... [BREAKPOINT HERE]
      }
  
      scene::ISceneNode* getNode() {
          return node;
      }
  };
  
  class Zombie : public GameObject {
  public:
      static const enum Animation {
          ZOMBIE_WALK,
          ZOMBIE_HURT,
          ZOMBIE_DIE,
          ZOMBIE_TWITCH,
          ZOMBIE_ATTACK,
          ZOMBIE_IDLE
      };
  
      //We only want to accepted animated mesh nodes for this object
      Zombie(int hp, scene::IAnimatedMeshSceneNode* inode) {
          ...
      }
  
      //Override the shot function
      void shot(int dmg) {
          ... [BREAKPOINT HERE]
      }
  
      //Animate the zombie
      void setAnimation(Animation anim) {
          ...
      }
  };
  </code></pre>
  
  <p>The member functions of the derived classes is never called, I am creating the objects like this</p>
  
  <p><code>Zombie target(hp, (scene::IAnimatedMeshSceneNode*)node);</code></p>
  
  <p>and calling the virtual function like this</p>
  
  <pre><code>for(int i = 0; (u32)i&lt;level-&gt;gameTargets.size(); i++) {
      if(selectedNode == level-&gt;gameTargets[i].getNode()) {
          level-&gt;gameTargets[i].shot(b-&gt;damage);
      }
  }
  </code></pre>
  
  <p>where b is a pointer to a bullet with a int variable damage and gameTargets contains GameObject</p>