+ 9
Why do we use (this->) when assigning values to properties in c++ classes using constructors
2 ответов
+ 7
We are accessing that object’s members and “this” is a keyword that points to the current object. It is not necessary unless you have parameters with the same name as the member you are trying to access. For example:
class myClass {
public:
myClass(int hi) {
//fine
hello = hi;
//not fine
hi = hi;
//instead
this->hi = hi;
}
int hello;
int hi;
};
If you don’t include this-> when there is a parameter with the same name, it will assume that you are talking about the parameter, not the member.
+ 5
thanks man @Jacob Pembleton this is the answer i was looking for✌️