I have to compare(>,<,==) two class object based upon different criteria, explained below.
class Student
{
int iRollNumber;
int iSection;
int iMarks;
}
- I want to do comparison with
iRollNumber, iSection, iMarks(Independently). - I want to do comparison with
iRollNumber, iSection(Combined). - I want to do comparison with
iMarks, iSection(Combined). - ……….
Currently I am achieving this with GetMethods() and comparing them using if elseif elseif.. structure.
This is leading to the messy code everywhere!
If I use operator overloading I have to decide on one way of comparison.
Please suggest a way to do it with elegant coding.
Or
Can it be possible to call operator overloading Polymorphically?
Write named functions:
although the need to do so many different kinds of comparison on a class is a bit unusual – you normally only need one or perhaps two. The functions should return the same kind of values as strcmp() does: