title: Why do you need pointers in this situation?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4403726/learning-c-polymorphism-and-slicing">Learning C++: polymorphism and slicing</a>  </p>
  </blockquote>
  
  
  
  <p>This is building off a question I asked before.
  The classes look like this:</p>
  
  <pre><code>class Enemy
  {
      public:
          void sayHere()
          {
              cout&lt;&lt;"Here"&lt;&lt;endl;
          }
          virtual void attack()
          {
          }
  };
  
  class Monster: public Enemy
  {
  
      public:
          void attack()
          {
              cout&lt;&lt;"RAWR"&lt;&lt;endl;
          }
  
  };
  class Ninja: public Enemy
  {
  
      public:
          void attack()
          {
  
              cout&lt;&lt;"Hiya!"&lt;&lt;endl;
          }
  };
  </code></pre>
  
  <p>I am new to C++ and I'm confused as to why this will only work with pointers (both Ninja and monster are derived from Enemy):</p>
  
  <pre><code>int main()
  {
      Ninja ninja;
      Monster monster;
  
      Enemy *enemies[2];
  
      enemies[0] = &amp;monster;
      enemies[1] = &amp;ninja;
  
      for (int i = 0; i &lt; 2; i++)
      {
          enemies[i]-&gt;attack();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Why can't I instead do this?:</p>
  
  <pre><code>int main()
  {
      Ninja ninja;
      Monster monster;
  
      Enemy enemies[2];
  
      enemies[0] = monster;
      enemies[1] = ninja;
  
      for (int i = 0; i &lt; 2; i++)
      {
          enemies[i].attack();
      }
  
      return 0;
  }
  </code></pre>