+ 1
Can any explain about this pointer in c++.with an simple example
this keyword
2 Answers
+ 4
class Test {
int num;
Test(int num) {this->num = num;};
bool test(int n) {return num == n;};
};
Because the overloading of num, the usage of this was required in the constructor to store the argument into the new object. In the test function, num isn't overloaded so I can optionally drop the this ('return this->num == n;' would work as well.)
+ 1
thanks...for answering