I came across the following function definition from a c++ textbook:
Vector& Vector::operator=(const Vector& a) {
double* p = new double[a.sz];
for (int i=0; i!=a.sz; ++i)
p[i] = a.elem[i];
delete[] elem;
elem=p;
sz=a.sz;
return *this;
}
I have a question about the last statement -- which returns *this
instead of this
. As far as I remember, this
in Java refers to the current object. Am I correct that this
in C++ refers to the pointer to the current object? If so, why is it designed in that way? Thanks.