title: smart pointer in constructor
body: <p>Story is: I have to make a class for my programming class and my custom project (Space Marine - yeah, I'm a bit of a fan) is in progress. But I found a problem I just can't simply solve. Here are some codes that I think are important:</p>
  
  <p>HEADER</p>
  
  <pre><code>class SpaceMarine
  {
  
  public:
  ...
      SpaceMarine(); // default constructor
      SpaceMarine(std::string name, 
                  unsigned int rang, 
                  Statystyki&amp; stats, 
                  std::auto_ptr&lt;Pancerz&gt; armor, Bron&amp; weapon);
  
  private:
  
      std::string name_;
      unsigned int ranga_;
      Statystyki* stats_;
      std::auto_ptr&lt;Pancerz&gt; armor_;
      Bron* weapon_;
      Experience experience_;
  </code></pre>
  
  <p>just to make it clear : "Statystyki", "Pancerz" and "Bron" are classes that are members of main class SpaceMarine. Project requirements: I have to make one smart pointer (here as auto_ptr).</p>
  
  <p>.CPP</p>
  
  <pre><code>SpaceMarine::SpaceMarine()
  {
      name_ = "John";
      stats_ = new Statystyki();
      weapon_ = new Bron(); 
      std::auto_ptr&lt;Pancerz&gt; armor_(new Pancerz());
  
  
     ranga_ = 0;
  }
  SpaceMarine::SpaceMarine(std::string name, 
                           unsigned int rang, 
                           Statystyki&amp; stats, 
                           std::auto_ptr&lt;Pancerz&gt; armor, Bron&amp; weapon) 
  : armor_(std::move(armor))
  {
      name_ = name;
      ranga_ = rang;
      stats_ = stats;
      armor_ = std::move(armor);
      weapon_ = weapon;
  }
  </code></pre>
  
  <p>Now, where the problem begins:
  This is the part of "main.cpp" file:</p>
  
  <pre><code>SpaceMarine SM1;
  SpaceMarine SM2("Azrael", 3, S2, **P2** , B2);
  </code></pre>
  
  <p>// S - Stats, P - armor, B-weapon class</p>
  
  <p>There is problem with this little thingy, called P2, which should be an auto_ptr to armor. I have armor object P2 declared previously. 
  I have problem "merging" auto_ptr into my constructor. Any ideas?</p>
  
  <p>Also, all advices about improving my code are welcome :)</p>
  
  <p>Matt</p>
  
  <p>Ps. My first post here! :D Go easy on me ^^</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks to user1158692 for tidying my code
  Thanks to Hansmaad and user1158692
  I wish I could make both your answers right for this probleme, as both helped me to deal with it ;)</p>
  
  <p>Here's the final code for future refrence:</p>
  
  <p>HEADER</p>
  
  <pre><code>SpaceMarine(std::string name, 
              unsigned int rang, 
              Statystyki&amp; stats, 
              Pancerz&amp; armor, 
              Bron&amp; weapon);
  </code></pre>
  
  <p>.CPP</p>
  
  <pre><code>SpaceMarine(std::string name, 
              unsigned int rang, 
              Statystyki&amp; stats, 
              Pancerz&amp; armor, 
              Bron&amp; weapon);
  
  {
      name_ = name;
      ranga_ = rang;
      stats_ = &amp;stats;
      std::unique_ptr&lt;Pancerz&gt; armor_(&amp;armor);
      weapon_ = &amp;weapon;
  } 
  </code></pre>
  
  <p>// and example of declaring it in main.cpp</p>
  
  <pre><code>Bron B2("Chainsword" , 0, 6);
  
  Pancerz P2("Power armor", 12);
  
  Statystyki S2(6,6,4,8,20);
  
  SpaceMarine SM2("Azrael", 3, S2, P2 , B2);
  </code></pre>