![]() |
In C++, operator overloading is used to redefine the behavior of already existing operators. Similarly, overloading the relational operators is commonly used to compare the instances of user-defined classes. By overloading these operators we can easily define the behavior of comparisons for the objects of a given class. In this article, we will see how to overload relational operators for a class in C++. Relational Operator OverloadingOverloading a relational operator is similar to any other operator overloading. We can easily implement it by overloading “ C++ Program to Implement Relational Operator OverloadingThe below example demonstrates how the overloading of relational operators is done in C++. C++
Output
obj1 is equal to obj2 obj1 is not less than obj2 obj1 is equal to obj2 obj1 is not greater than obj2 obj1 is less than or equal to obj2 obj1 is greater than or equal to obj2 Explanation: In the above program the overloading of all the relational operators ( |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |