How can it be useful to overload the “function call” operator?

后端 未结 7 428
终归单人心
终归单人心 2020-12-02 20:43

I recently discovered that in C++ you can overload the \"function call\" operator, in a strange way in which you have to write two pair of parenthesis to do so:



        
相关标签:
7条回答
  • 2020-12-02 21:44

    A algorithm implemented using a template doesn't care whether the thing being called is a function or a functor, it cares about the syntax. Either standard ones (e.g. for_each()) or your own. And functors can have state, and do all kinds of things when they are called. Functions can only have state with a static local variable, or global variables.

    0 讨论(0)
提交回复
热议问题