Hey guys,
So about a week ago I was a bit stuck on how to number of comparisons a particular program makes and asked for help here (http://www.cplusplus.com/forum/beginner/129822/ )
Someone suggested the following code
struct myCompare {
booloperator ()(int i, int j, int comparisonMethod) {
counter++;
switch (comparisonMethod) {
case 0: return i == j;
case 1: return i > j;
case 2: return i >= j;
case 3: return i < j;
case 4: return i <= j;
}
returnfalse;
}
int count() const { return counter; }
private:
staticint counter;
}compare;
int myCompare::counter = 0;
int main()
{
compare(3, 4, 1);
return 0;
}
At that time I basically had no clue on classes/structs and overloading. Now after reading up a bit on them I have some questions.
What is the point of overloading the () operator here? Could you not just make another function to do the same thing. Does overloading the () operator give any advantage? Also what exactly is the point of having private and public parts of a class?