Using these two previous threads as examples
First thread: Why does overloaded assignment operator return reference to class?
Second thread: Why must the copy assignment operator return a reference/const reference?
Is the return type of an overloaded assignment operator a class or a reference to a class? I have seen both:
Point& Point::operator = (const Point& sourcePoint)
{
// As in the first thread I pasted above
return *this;
}
And
Point Point::operator = (const Point& sourcePoint)
{
// As in the second thread I pasted above
return *this;
}
Which is right?
Similarly, what's the difference between:
int exFunction()
{
int i = 5;
int* iPtr = &i;
return *iPtr;
}
Versus:
int& exFunction2()
{
int j = 5;
int* jPtr = &j;
return *jPtr;
}
Thanks!