0

I'm wondering if a if statement or a returnquits early if possible. E.g. in this code:

bool Point::operator==(const Point &rhs) const
{
  return (x==rhs.x //if the x's are not equal, there's no point in comparing y and z.
          && y==rhs.y
          && z==rhs.z);
}

or this:

bool Point::operator==(const Point &rhs) const
{
  if (x==rhs.x //same as above
      && y==rhs.y
      && z==rhs.z)
    return true;
  return false;
} 

Further, is any one of the above version better?

Cœur
  • 37,241
  • 25
  • 195
  • 267
dani
  • 3,677
  • 4
  • 26
  • 60

0 Answers0