0

How to call overloaded operator from different overloaded operator

Hi I have overloaded < operator as well as > operator for a custom class. I would like to remove one function definition and Instead call other one with negate effect. For example Call < overloaded operator and return reverse of result as output of > operator. https://sololearn.com/compiler-playground/cE5smx6LGeKH/?ref=app

12th Dec 2024, 2:16 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
6 Respostas
+ 1
The link you have shared is broken and I cannot open it from Windows OS laptop.
13th Dec 2024, 2:37 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
I can check link in android app. No, question is not same. Here, I am ok with Two definition but in a different way Something like below: bool islessthan(int a,int b) { return a<b; } bool isgreateethan(int a,int b) { return !islessthan(a,b); } Basically, I need to call operator < from operator >
14th Dec 2024, 4:11 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
I understand your point of inequality and < with > but I need a mechanism if available to call one overloaded operator from another overloaded operator
14th Dec 2024, 4:36 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
13th Dec 2024, 6:08 AM
Bob_Li
Bob_Li - avatar
0
maybe. But wouldn't your isgreaterthan be actually be >= ? !(a<b) also includes a==b it might or not matter, depending on your use case, like sorting, but > would be wrong if you were to use it for two equal values... it would be better to use bool isgreaterthan(int a, int b){ return islessthan(b, a); }
14th Dec 2024, 4:21 AM
Bob_Li
Bob_Li - avatar
0
relational operators can be constructed from at minimum of 2 operations. Since < is required by the stl, the other would be == define these: a < b a less than b a == b a equal to b from those two we can derive: b < a a greater than b a > b !(a == b) a not equal to b a != b !(a < b) a greater than or equal to b a >= b !(b > a) a less than or equal to b a <= b https://www.geeksforgeeks.org/relational-operator-overloading-in-cpp/
14th Dec 2024, 4:55 AM
Bob_Li
Bob_Li - avatar