title: C++, modification of (random) object in a queue not desired, object pointors
body: <p>I've created a queue (thanks to vector library) of object pointors.</p>
  
  <pre><code>std::vector&lt;Polygon*&gt;queue;
  </code></pre>
  
  <p>My class Polygon is the mother class of all the others, basicaly the aim of it is to draw a shape. So the polygon is drawing a polygon, the rectangle a rectangle... with both * and # chosen at random. It actually perfectly works.</p>
  
  <p>So I wanted to create several of these drawings and put them in a queue and when the program ends display all the shapes (using a FIFO). At first it seems to works, but diging a bit I realized that the drawing where different. </p>
  
  <p>For example the rectangle will still be a rectangle, with the same dimension, but the patern of * and # will be different. So it means that the figure has not been saved, but its parameters have been. And the queue is rebuilding those.</p>
  
  <p>What I would like to do is to save the same shape, what did I do wrong ?</p>
  
  <pre><code>/* 
   * File:   main.cpp
   * Author: vfortineau
   *
   * Created on may 12nd 2015, 10:25
   */
  
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include "Polygon.h"
  #include "Rectangle.h"
  #include "Square.h"
  #include "IsoscelesTriangle.h"
  #include "ReversedTriangle.h"
  #include "Diamond.h"
  
  using namespace std;
  
  /*
   * 
   */
  int main(int argc, char** argv) {
      int choice;
      int _height;
      int _width;
      int _posi;
      int i=0;
      Polygon* polymorph;
      std::vector&lt;Polygon*&gt;queue;
      while (1)
      {
  
          cout &lt;&lt; "\n\tPlease type one of the following command :\n" &lt;&lt; endl;
          cout &lt;&lt; "\t********************************************\n"&lt;&lt;\
                  "\t* 1 - Upright isosceles triangle           *\n" &lt;&lt; \
                  "\t* 2 - Inverted isosceles triangle          *\n" &lt;&lt; \
                  "\t* 3 - Rectangle                            *\n" &lt;&lt; \
                  "\t* 4 - Square                               *\n"&lt;&lt; \
                  "\t* 5 - Diamond                              *\n"&lt;&lt; \
                  "\t* 6 - Polygone                             *\n" &lt;&lt; \
                  "\t* 0 - Exit Program                         *\n" &lt;&lt; \
                  "\t********************************************" &lt;&lt; endl;
          cin &gt;&gt; choice;
          switch(choice)
          {
              case 1:
                  cout &lt;&lt; "Choose the size of the height (please type an integer) : \n";
                  cin &gt;&gt; _height;
                  cout &lt;&lt; "Choose the position (please type an integer) : \n ";
                  cin &gt;&gt; _posi;
                  polymorph = new IsoscelesTriangle(_height, _posi);
                  polymorph-&gt;drawShape();
                  queue.push_back(polymorph); 
  
                  break;
              case 2:
                  cout &lt;&lt; "Choose the size of the height (please type an integer) : \n";
                  cin &gt;&gt; _height;
                  cout &lt;&lt; "Choose the position (please type an integer) : \n ";
                  cin &gt;&gt; _posi;
                  polymorph = new ReversedTriangle(_height, _posi);
                  polymorph-&gt;drawShape();
                  queue.push_back(polymorph); 
                  break;
              case 3:
                  cout &lt;&lt; "Choose the size of the height (please type an integer) : \n";
                  cin &gt;&gt; _height;
                  cout &lt;&lt; "Choose the size of the width (please type an integer) : \n";
                  cin &gt;&gt; _width;
                  cout &lt;&lt; "Choose the position (please type an integer) : \n ";
                  cin &gt;&gt; _posi; 
                  polymorph = new Rectangle(_height, _width, _posi);
                  polymorph-&gt;drawShape();
                  queue.push_back(polymorph); 
                  break;
              case 4:
                  cout &lt;&lt; "Choose the size of the sides (please type an integer) : \n";
                  cin &gt;&gt; _height;
                  cout &lt;&lt; "Choose the position (please type an integer) : \n ";
                  cin &gt;&gt; _posi; 
                  polymorph = new Square(_height, _width, _posi);
                  polymorph-&gt;drawShape(); 
                  queue.push_back(polymorph); 
                  break;
              case 5:
                  cout &lt;&lt; "Choose the size of the vertical diagonal (please type an integer) : \n";
                  cin &gt;&gt; _height;
                  cout &lt;&lt; "Choose the position (please type an integer) : \n ";
                  cin &gt;&gt; _posi; 
                  polymorph = new Diamond(_height, _posi);
                  polymorph-&gt;drawShape();
                  queue.push_back(polymorph); 
                  break;
              case 6:
                  cout &lt;&lt; "Choose the size of the height (please type an integer) : \n";
                  cin &gt;&gt; _height;
                  cout &lt;&lt; "Choose the size of the width (please type an integer) : \n";
                  cin &gt;&gt; _width;
                  cout &lt;&lt; "Choose the position (please type an integer) : \n ";
                  cin &gt;&gt; _posi; 
                  polymorph = new Polygon(_height, _width, _posi);
                  polymorph-&gt;drawShape(); 
                  queue.push_back(polymorph); 
                  break;
              case 0:
                  while(not queue.empty())
                  {
                      i++;
                      cout &lt;&lt; endl &lt;&lt; "\t Figure " &lt;&lt; i &lt;&lt; endl;
                      cout &lt;&lt; "\t---------\n\n";
                      queue[0]-&gt;drawShape();
                      queue.erase(queue.begin());                    
                  }
                  return 0;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>I'm joining as an example a version of a drawShape() function but I don't think the problem is coming from here.</p>
  
  <pre><code>void IsoscelesTriangle::drawShape()
  {
      srand(time(NULL));
      int random=0;
      for(int i=0; i&lt;height; i++)
      {
          position();
          for(int j=0; j&lt;height-(i+1); j++)
          {
              std::cout &lt;&lt; "  ";
          }
          for (int k=0; k&lt;(2*i+1); k++)
          {
              random=rand()%2;
              if (random==0) std::cout &lt;&lt; "* ";
              else std::cout &lt;&lt; "# ";            
          }
          std::cout &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>height is a protected member of Polygon, and position a public function of Polygon.</p>
  
  <p><a href="http://i.stack.imgur.com/lznks.png" rel="nofollow">An example of output</a></p>