I recently discovered a great C ++ feature that allows programmers to overload operations on the classes they create. As a way to get into this topic, I decided to try to create my own vector class .
As a small test satisfying my curiosity, I recently did the following to overload the equality operators for my class:
95 bool Vect::operator==(const Vect& rhs){
96 return this->getCoord() == rhs.getCoord()
98 }
99
100 bool Vect::operator!=(const Vect& rhs){
101 return !(*this == rhs);
102 }
This compiles and works correctly. However, I had a question about whether this was good / bad practice (and why!). I don’t want to get into the habit of doing it if it’s bad, or to encourage myself to continue using it if it’s good.
source
share