Overloading the multiple operators together in a C++program.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
// overloading the logical opertor - Triangle is Isosceles or not #include<iostream> using namespace std; class T4Tutorials { private : int number; public : void input() { cin>>number; } int operator >(T4Tutorials formal_Arguments) { if(number> formal_Arguments.number) return 1; else return 0; } int operator ==(T4Tutorials formal_Arguments) { if(number== formal_Arguments.number) return 1; else return 0; } }; int main() { T4Tutorials object1, object2; cout<<"Please enter the first number. "; object1.input(); cout<<" Please enter the second number."; object2.input(); //DONT NEED TO OVERLOAD the or operator explicitly - it works automatically if(object1 == object2 || object1 > object2) { cout<<"The VALUE OF OBJECT 1 IS EQUAL TO OBJECT 2 OR VALUE OF OBJECT 1 IS GREATER THEN VALUE OF OBJECT 3."; } return 0; } |
Output
Please enter the first number. 7
Please enter the second number. 5
The VALUE OF OBJECT 1 IS EQUAL TO OBJECT 2 OR VALUE OF OBJECT 1 IS GREATER THEN VALUE OF OBJECT 3
FAQ
Overloading the multiple operators together in a C++program.
Overloading the two operators in a C++program.
Overloading the equal and greater operators in a C++program.
Overloading the ==, > and || operators in a C++program.