Alex Rivera | Logout

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

Asked 2010-02-28T02:54:44.180
29

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?

Edit
Report

1 Answer

1

If you're making a class that encapsulates a function pointer, this might make the usage more obvious.

answered 2010-02-28T02:56:52.833

Your Answer