title: What is happening in this C++ constructor?
body: <p>In the below <a href="http://gameprogrammingpatterns.com/type-object.html" rel="nofollow noreferrer">class</a>, the member variable <code>health_</code> is being initialised with the use of a colon, and before the constructor's main body:</p>
  <pre><code>class Monster
  {
  public:
    virtual ~Monster() {}
  
  protected:
    Monster(int startingHealth)
    : health_(startingHealth)
    {}
  
  private:
    int health_; // Current health.
  };
  </code></pre>
  <p>Why is <code>health_</code> not initialised within the constructor's main body like this:</p>
  <pre><code>class Monster
  {
  public:
    virtual ~Monster() {}
  
  protected:
    Monster(int startingHealth)
    {
      health_ = startingHealth;
    }
  
  private:
    int health_; // Current health.
  };
  </code></pre>
  <p>Is the first example different to the second?</p>