for example,
in this one,
I ‘m not very understand about the this pointer,
this question is not about operator+ overload,
is about the this pointer, and its relation between the class,
*this pointer point to what thing?
thank u very much!
class Integer {
int i;
public:
Integer(int ii): i(ii) { }
const Integer operator+(const Integer& rv) const {
cout<<"operator+"<<endl;
}
Integer&
operator+=(const Integer& rv) {
i += rv.i;
return *this;
}
}
thisidentifies a special type of pointer.IF you create an object named x of class A, and class A has a nonstatic member function f(). If you call the function x.f(), the keyword this in the body of f() stores the address of x. You cannot declare the this pointer or make assignments to it.Basically
thispointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions.