0
What's wrong here?
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/
+ 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
+ 1
Is there a way like java?
this.name = name
?
Or it must have a different name?