Weird polymorphism c++? -
this question has answer here:
anyone can explain weird bit in line of code me?
classa::classa(std::string aname) : name(aname)
appearantly, declaration of class
class classa { public: std::string name; classa(std::string aname); };
and weird line of code appeared in cpp file
classa::classa(std::string aname) : name(aname)
it's not polymorphism right? then, it?
this constructor initialization list:
classa::classa(std::string aname) : name(aname) // constructor initialization list { // ctor body. name initialized here }
it means data member name
gets initialized value of aname
.
it orthogonal polymorphism.
Comments
Post a Comment