... because when you do that, your class (or struct) becomes a functor.
Functors are commonly used with the function templates from the algorithm library.
You are however encouraged to use lambda functions instead of functors if your C++ compiler supports them.
The good thing about providing a function call operator rather than some other named member function is that
a) the calling code doesn't need to know which function to call (imagine how much more awkward it would be to sort a vector, for example, if you had to provide both the comparison object and a member function pointer to call in it)
b) it works exactly the same way whether a function, a function pointer, a lambda expression, a bind expression, or a hand-written functor is used. In short, it's simple.
Sure, here's something to sink your teeth into, along the same vein ne555 was going, but with strings instead of points and using std::sort/std::generate. You will find a few overloaded operator() within.
How do you get to overloaded operators but haven't covered vectors at all? =/
A vector is basically the std:: library version of a dynamic array, and it's not terribly complex after you've had a little experience using std:: containers/algorithms.
> How do you get to overloaded operators but haven't covered vectors at all?
Functions -> Overloading functions -> Templates.
Operators are functions with a special signature.
Should I just save this code for now and either pm you or make a new thread explaining any further confusion?
Overloaded operator() gets most of its use through interfacing with library-ish code. Maybe just note for the moment that it is a way to make an object behave like a function. It will become more useful, the more you know.