Difference between revisions of "Talk:CPP/Classes/ConstructorInheritance"
From ProgrammingExamples
< Talk:CPP
(Created page with 'both ctors in the subclasses Pilot and BlimpPilot set the Person's member variable m_Name<br> <code> Pilot(std::string &name) : Person(name) {m_Name = name;} BlimpPilot(s…') |
Daviddoria (Talk | contribs) |
||
Line 21: | Line 21: | ||
BlimpPilot(std::string &name) : Pilot(name) {} // calls Pilot' ctor | BlimpPilot(std::string &name) : Pilot(name) {} // calls Pilot' ctor | ||
</code> | </code> | ||
+ | |||
+ | : Cool - I'm out of town for a couple of weeks. Feel free to change. I've marked it in my "follow ups" for when I get back if you don't get to it. Thanks again for your interest and help with starting up this project! [[User:Daviddoria|Daviddoria]] 06:09, 4 July 2010 (UTC) |
Latest revision as of 02:09, 4 July 2010
both ctors in the subclasses Pilot and BlimpPilot set the Person's member variable m_Name
Pilot(std::string &name) : Person(name) {m_Name = name;} BlimpPilot(std::string &name) : Pilot(name) {m_Name = name;}
this is not needed and already done by the Person ctor :
Person(std::string name) { m_Name = name; }
thus, to avoid unneeded (and error prone) work , the ctors should be
Person(std::string name){m_Name = name;} // does the affectation of m_Name Pilot(std::string &name) : Person(name) {} // calls 'Person' ctor BlimpPilot(std::string &name) : Pilot(name) {} // calls Pilot' ctor
- Cool - I'm out of town for a couple of weeks. Feel free to change. I've marked it in my "follow ups" for when I get back if you don't get to it. Thanks again for your interest and help with starting up this project! Daviddoria 06:09, 4 July 2010 (UTC)