18th Jan 2021, 3:00 PM
Yahel
Yahel - avatar
3 ответов
+ 3
Yes we can use `this` to distinct member name from setter's argument's name, as follows; // in name setter this->name = name; // in age setter this->age = age; However, it is recommended to use constructor initializer instead, as covered in this chapter, https://www.sololearn.com/learn/CPlusPlus/1896/
18th Jan 2021, 3:21 PM
Ipang
+ 2
You are trying to assign "name" to "name", these setters parameters must be named different than class members. name = name; is the problem, same about age setter void setName(string _name){ name = _name; } This will work
18th Jan 2021, 3:08 PM
Michal Doruch
+ 1
Is there a way like java? this.name = name ? Or it must have a different name?
18th Jan 2021, 3:11 PM
Yahel
Yahel - avatar