+ 1

Can any explain about this pointer in c++.with an simple example

this keyword

24th Oct 2017, 4:12 AM
B.VIDYADHAR VIJJU
B.VIDYADHAR VIJJU - avatar
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.)
24th Oct 2017, 4:38 AM
John Wells
John Wells - avatar
+ 1
thanks...for answering
24th Oct 2017, 4:44 AM
B.VIDYADHAR VIJJU
B.VIDYADHAR VIJJU - avatar