I am very new to C++, and am following along with this tutorial and have come across this class constructor:
class Player: public Entity
{
private:
std::string m_Name;
public:
Player(const std::string& name)
: m_Name(name) {}
std::string GetName() override
{
return m_Name;
}
};
So, from what I understand, when we create an instance of the class, we pass a name into the constructor, and it sets m_Name = name, but why is it defined in a weird way and not inside the {} body of the constructor?
I have tried the alternative below, and it works all the same:
Player(const std::string& name)
{
m_Name = name;
}
I am just wondering what is going on in the first example.