title: Pushing local objects into a list
body: <p>I have a class </p>
  
  <pre><code>class Invader
  {
  public:
      Invader();
      ~Invader();
  public:
      void Init(InvaderTypes invadertype, CIw2DImage *AlienImage);
      void Update(float dt);
      void Render();
      void SetAlienImage(CIw2DImage *image){ ImageAlien = image; }
  
      void        setVisible(bool show)       { Visible = show; }
      bool        isVisible() const           { return Visible; }
  
  
      Iw2DSceneGraph::CSprite         *AlienSprite;
      Iw2DSceneGraph::CAtlas          *AlienAtals;
      CIw2DImage                      *ImageAlien;
      std::list&lt;Bullet*&gt;              *Bullets;
      CIwFMat2D                       Transform;              // Transform matrix
  
      bool                             Visible;                // Sprites visible state
      bool                             Canfire;
  };
  
  
  void Invader::Init(InvaderTypes invadertype, CIw2DImage *AlienImage)
  {
      if (invadertype == InvaderTypes::TOP_ALIEN)
      {
          //SetAlienImage(AlienImage);
          mImageAlien = AlienImage;
          // Create EnemyTop atlas
          int frame_w = (int)(mImageAlien-&gt;GetWidth() / 2);
          int frame_h = (int)(mImageAlien-&gt;GetHeight());
          AlienAtals = new CAtlas(frame_w, frame_h, 2, mImageAlien);
          AlienSprite = new CSprite();
          AlienSprite-&gt;m_X = 0;
          AlienSprite-&gt;m_Y = 0;
          AlienSprite-&gt;SetAtlas(AlienAtals);
          AlienSprite-&gt;m_W = (float)AlienAtals-&gt;GetFrameWidth();
          AlienSprite-&gt;m_H = (float)AlienAtals-&gt;GetFrameHeight();
          AlienSprite-&gt;m_AnchorX = 0.5;
          AlienSprite-&gt;SetAnimDuration(2);
      }
      else if (invadertype == InvaderTypes::MIDDLE_ALIEN)
      {
  
      }
      else if (invadertype == InvaderTypes::LAST_ALIEN)
      {
  
      }
  
  
      Visible = true;
      Bullets = new std::list&lt;Bullet*&gt;();
      Canfire = true;
  }
  
  
  
  Invader::Invader()
      {
  
      }
      Invader::Invader(const Invader&amp;other)
      {
          AlienAtals = new CAtlas();
          AlienSprite = new CSprite();
          *AlienAtals = *other.AlienAtals;
          *AlienSprite = *other.AlienSprite;
      }
  </code></pre>
  
  <p>I try to initialize it by:</p>
  
  <pre><code>list&lt;Invader&gt; *invaders = new list&lt;Invader&gt;();
  
      int spacing = 10;
  for (int i = 0; i &lt; 5; i++)
  {
      Invader invader;
      invader.Init(TOP_ALIEN, gameResources-&gt;getAlienImageTop());
      invader.AlienSprite-&gt;m_X = 50 + spacing;
      invaders-&gt;push_back(invader);
      spacing += 50;
  }
  </code></pre>
  
  <p>After pushing the object invader to the list, at the end the invaders list holds pointers that are not initialized. All the pointers got lost the references. I wonder why ? </p>