Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 28. Overloading Operators > COMPARISON OPERATORS

28.4. COMPARISON OPERATORS

The comparison operators are simply binary operators that return a Boolean result. The only oddity to these is that they come in pairs. For example, if you define =, then you must also define <>. The pairs are = and <>, < and >, and <= and >=.

The following code shows how you could overload the < and > operators for the ComplexNumber class by comparing the numbers' magnitudes:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint