int vecteur3d::operator !=(vecteur3d v)
{
return !((*this)==v);
}
The function itself tells you that it will return an integer, then no, the function will not return a pointer but simply an integer. What we should ask ourselves here is what is the sense of this operator returning an integer instead of a Boolean, which would be natural.
What does that return
do?
return !((*this)==v);
// ^^^^^
The asterisk operator *
is used in this case to dereference the pointer, that is, it is a way to access the content managed by the pointer:
int* ptr = new int(10);
int var = *ptr; // var = 10
std::cout << var;
We continue ...
return !((*this)==v);
// ^^
We have already seen that with the operator *
we are accessing the pointed object, which in this case is type vecteur3d
. The comparison operator is comparing this object with v
, which is also type vecteur3d
. The result of the comparison will be a Boolean.
return !((*this)==v);
// ^
This last operator will invert the value returned by the previous comparison. If it turns out that *this
equals v
the comparison operator will return true
and this operator will convert it to false
and vice versa.
If we break the line of code, the sequence of instructions is better:
int vecteur3d::operator !=(vecteur3d v)
{
vecteur3d yo = *this;
bool iguales = (yo==v);
return !iguales;
}
In summary. This is a simple way to implement the operator "other than" without having to repeat the logic implemented in the comparison operator.