Greater than > Operator Overloading C++
Greater than > Operator Overloading in C++ and Object Oriented Programming (OOP).
C++ Program to overload the Greater than > operator
In this program we try to overload the > operator with C++. Greater number C++ Program with operator overloading.
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 | // > (Greater than)Operator overloading #include<iostream> using namespace std; class T4Tutorials { private : int num; public : void input() { cin>>num; } int operator >( T4Tutorials x) { if(num>x.num) return 1; else return 0; } }; int main () { T4Tutorials n1,n2; cout<<"Please enter 1st number. "; n1.input(); cout<<" Please enter 2nd number."; n2.input(); if(n1>n2) { cout<<"n1 is greater than n2. "; } else { cout<<"n1 is not greater than n2. "; } return 0; } |
Output
Please enter 1st number. 6
Please enter 2nd number. 5
n1 is greater than n2.
Video Lecture
FAQ
- Greater than operator overloading in c++ example.
- Greater than operator overloading.
- > operator overloading in c++ example.
- Relational operator overloading in c++ with programs.
- Overload comparison operator c++.
- Overloading stream insertion (<>) operators in C++.