Detailed difference between functor's call and function call?

Viewed 3010

The key reason this works is that for_each () doesn’t actually assume its third argument to be a function. It simply assumes that its third argument is something that can be called with an appropriate argument. A suitably defined object serves as well as – and often better than – a function. For example, it is easier to inline the application operator of a class than to inline a function passed as a pointer to function. Consequently, function objects often execute faster than do ordinary functions. An object of a class with an application operator (§11.9) is called a functionlike object, a functor, or simply a function object.

[Stroustrup, C++ 3rd edition, 18.4-last paragraph]

  1. I always thought that the operator ( ) call is just like function call at runtime. how does it differ from a normal function call?

  2. Why is it easier to inline the application operator than a normal function?

  3. How are they faster than function call?

3 Answers
Related