title: Overloading the comparison operator for object members
body: <p>Say I have a class called book:</p>
  
  <pre><code>class Book {
      int i;
  
      public:
          Book(int ii)
          : i(ii) {
          }
  
          int ISBN() {
              return i;
          }
  };
  </code></pre>
  
  <p>I want to overload the comparison operator for the Book class, so that I can create a bool function that will compare the member "i" when it comes across book1==book2.</p>
  
  <pre><code>bool is_same() {
      return (book1==book2) ? true : false;
  }
  </code></pre>
  
  <p>How would I go about this? This is the current operator overload function I have, it gives me an "invalid initialization of non-const reference of type 'Book&amp;' from an rvalue of the type 'bool'" error. I currently have my overloaded function inside of the class Book as a public function.</p>
  
  <pre><code>Book&amp; operator==(const Book&amp; b) const {
          return ISBN() == b.ISBN();
      }
  </code></pre>
  
  <p>I'm relatively new to operator overloading, I have sifted through many answers but none of them resolve my issue. I understand how one could simply do book1==book2, but that would only return true if every single member was of the same value. In this case I have more than just one, but I only want to return true if "i" is the same for both objects.</p>