How can it be useful to overload the “function call” operator?
问题 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: class A { int n; public: void operator ()() const; }; And then use it this way: A a; a(); When is this useful? 回答1: This can be used to create "functors", objects that act like functions: class Multiplier { public: Multiplier(int m): multiplier(m) {} int operator()(int x) { return multiplier * x; } private: int multiplier; }; Multiplier