Search Results

Search found 1 results on 1 pages for 'philosphical'.

Page 1/1 | 1 

  • Is this overly clever or unsafe?

    - by Liberalkid
    I was working on some code recently and decided to work on my operator overloading in c++, because I've never really implemented it before. So I overloaded the comparison operators for my matrix class using a compare function that returned 0 if LHS was less than RHS, 1 if LHS was greater than RHS and 2 if they were equal. Then I exploited the properties of logical not in c++ on integers, to get all of my compares in one line: inline bool Matrix::operator<(Matrix &RHS){ return ! (compare(*this,RHS)); } inline bool Matrix::operator>(Matrix &RHS){ return ! (compare((*this),RHS)-1); } inline bool Matrix::operator>=(Matrix &RHS){ return compare((*this),RHS); } inline bool Matrix::operator<=(Matrix &RHS){ return compare((*this),RHS)-1; } inline bool Matrix::operator!=(Matrix &RHS){ return compare((*this),RHS)-2; } inline bool Matrix::operator==(Matrix &RHS){ return !(compare((*this),RHS)-2); } Obviously I should be passing RHS as a const, I'm just probably not going to use this matrix class again and I didn't feel like writing another function that wasn't a reference to get the array index values solely for the comparator operation.

    Read the article

1