Let's say I define, instantiate, and use the adder functor as follows:
class SomeAdder {
public:
SomeAdder(int init_x): x(init_x) {}
void operator()(int num) { cout << x + num <<endl; }
private:
int x;
};
SomeAdder a = SomeAdder (3);
a(5);
SomeAdder b(5);
b(5);
The constructor and the overloaded operator ()are called using double brackets and have the same parameter types. How will the compiler determine which function to use during instances SomeAdderand "function calls" to implement the correct behavior? The answer seems to be obvious on the surface, but I just can't plunge into this thought.
Thank you for your time!
source
share