title: How to loop through class objects in C++
body: <p>My question is How can I have combat for all enemies by having only 1 function?</p>
  
  <p>At the moment I create my enemies by writing <code>Enemy</code> (class) and giving it <code>object + number</code> name, then I just give some inputs and it looks like:</p>
  
  <pre><code>Enemy object1(1, 20, '/', "AQUA", 1);
  Enemy object2(5, 40, '/', "YELLOW", 2);
  Enemy object3(10, 60, '/', "WHITE", 3);
  </code></pre>
  
  <p>Then I have a runtime for Combat and I run an awful while loop:</p>
  
  <pre><code>while (object1.getHp() &gt; 0)
  </code></pre>
  
  <p>to run my combat code.</p>
  
  <p>So now I need to have just one combat function to run all different enemies, I already tried a lot of  thing but nothing seems to work. Any idea on what can I do?</p>
  
  <p>Sounds and looks dumb but I really can't guess anything to do about it, already lost tons of hours looking for a solution.</p>