Logical Or operator Overloading C++
How to use the OR Operator in operator overloading in C++.
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 42 |
// overloading the logical opertor - Triangle is Isosceles or not #include<iostream> using namespace std; class T4Tutorials { private : int num; public : void input() { cin>>num; } int operator ==(T4Tutorials formal_parameter) { if(num== formal_parameter.num) return 1; else return 0; } }; int main() { T4Tutorials object1, object2, object3; cout<<"Please enter side 1 of the triangle. "; object1
.input(); cout<<" Please enter side 2 of the triangle."; object2.input(); cout<<" Please enter side 3 of the triangle."; object3.input(); //Here, DONT NEED TO OVERLOAD the or operator explicitly - it works automatically if(object1 == object2 || object1 == object3 || object2 == object3 ) { cout<<"The Triangle is Isosceles"; } else { cout<<"The Triangle is not Isosceles."; } return 0; } |
Output
Please enter side 1 of the triangle. 4
Please enter side 2 of the triangle. 4
Please enter side 3 of the triangle.4
FAQ
Overloading the logical Or operator C++.
How to overload || operator in C++?
How to overload logical operators in C++?
How to overload OR operator in C++?
Overloading the OR operator in C++.
Write a C++ program to overload the OR operator.
Develop a C++ program to overload the || operator.
Write a C++ program to show the results after overloading theĀ OR || operator.
Overloading the OR operator.
Write a C++ program to show the results after overloading theĀ OR || operator.