lundi 2 janvier 2017

Best way to initialize a constructor that does more than initialize

I'm new to c++, and I'm just looking for some insight into a question I have with c++ 11 constructors. I've heard that initializer list are the best way to initialize variables in a constructor. If you use and initializer list, you have to implement constructor only in header file. I don't know what the "industry standard" is on the topic, so I ask you.

Constructor 1 (Clouds.h)

   Clouds(float x, float y, sf::Texture texture, std::mt19937 randGen) 
                                : x(x), y(y), defaultX(x), defaultY(y) 
        {
            cloudSprite.setTexture(texture);
            cloudSprite.setPosition(x, y);
        };

Constructor 2 (Clouds.cpp)

    Clouds::Clouds(float x, float y, sf::Texture texture, std::mt19937 randGen)
{
    Clouds::x = x;
    Clouds::y = y;
    Clouds::cloudSprite.setTexture(texture);
    Clouds::cloudSprite.setPosition(x, y);
}

This situation may not matter, but there is a lot of old content, I know you have to be careful what you read, that doesn't apply anymore with c++ 11. Is this one of those instances?

Aucun commentaire:

Enregistrer un commentaire