0
class Entity {
public:
    std::string GetName() { return "Entity:"; }
};

class Player : public Entity {
private :
    std::string m_name;

public :
    Player(const std::string& name) : m_name(name) {}

    std::string GetName() { return m_name; }


};

above is C++ class definition i'm studying currently. Everthing looks OK but i don't understand the part,

Player(const std::string& name) : m_name(name) {}

Why do I need : m_name(name) part? what is the use of that definition? So far what I understood is that it changes the variable m_name to be the parameter name of Player constructor... is that it?

  • Which C++ textbook are you "studying"? Doesn't it have a chapter on constructors and class member initialization? – Sam Varshavchik Aug 12 '21 at 01:02
  • Studying code is only a small fraction of the game. You MUST get [some good books](https://stackoverflow.com/questions/388242) if you really want to learn C++ in a reasonable timeframe. It's too complicated a language to try to muddle your way though with code samples found on the Internet. – user4581301 Aug 12 '21 at 01:07
  • @user4581301 that is so true. I must find a good source and start from there to master it.. Thank you! – kyuho Lee Aug 13 '21 at 10:00

0 Answers0