Issue regarding Initialization Lists C++
<p>For example, say I have the following code;</p>

<pre><code>class Foo
{
    public:
    Foo(int x) : _foo(x)
    {

    }

    private:
    int _foo;

    protected:
    std::string _bar;
};

class Bar : public Foo
{
    public:
    Bar() : Foo(10), _temp("something"), _bar("something_else")
    { 

    }
    private:
    std::string _temp;
};

int main()
{
    Bar stool;
}
</code></pre>

<p>The code doesn't run because _bar is of the class Foo and it doesn't appear to know it exists, so is this not how you would go about doing it? Or would you just have _bar in Foo's constructor? This would work but what if _bar doesn't always have to be assigned something?</p>

<p>Edit: Below is the real code I was using;</p>

<pre><code>Entity::Entity(GameState *state, bool collidable) 
    :_isLoaded(false), _state(state), alive(true), collidable(collidable),               name(entityDetault)
</code></pre>

<p>{</p>

<p>}</p>

<pre><code>Entity::Entity(GameState *state, bool collidable, entityName _name)
    :_isLoaded(false), _state(state), alive(true), collidable(collidable), name(_name)
{

}
</code></pre>

<p>and then the child class would use this constructor;</p>

<pre><code>Player::Player(GameState *state) 
: Entity(state,true,entityName::entityPlayer), health(100),bulletSpeed(600),_colour(sf::Color(128,255,86,255))
</code></pre>

<p>Does this all look correct now? Slightly better than doing it all in the constructor body.</p>
