Why would you create a class with one single member which is an operator()?

Viewed 703

I have tried to find out -out there- a good technical reason for defining a class which contains only one member and this member happens to be a operator().

I stumbled upon someone who -for whatever the reason- created a namespace containing a couple of classes, but each class contains only one operator() as a member.

It is clear to me that these classes might then be used as if they were methods (very likely), but why is this a good technical approach (I assume there is a good one), rather than simply defining a set of different methods within a singleton class which in this particular case would belong to the namespace I mentioned lines above.

The namespace looks something like:

namespace myNamespace {
   class ClassA {
   public:
      void operator()();
   };

   class ClassB {
   public:
      int operator()(arg1, arg2);
   };

   ...
}

Is this simply a matter of personal taste/style or is this the expression of advance/sophisticated design? I assume this design encompass some wise knowledge that I haven't gathered yet, but on the other hand I haven't found a piece of article or question discussing this - which makes me doubt about such "wise knowledge" in the design.

What does the experts here have to say?

Thanks in advance!

EDIT

Hello again! I accept this question to be a REPEATED question, whose answer is found here.

The term Functor was unknown to me and while trying to find an answer to my doubt (prior to this question's submission), I did not see any references to this term.

I still accept the answer from SergeyA, because his answer introduced me to the term and his explanation is answering my question. His answer -from my point of view- is extended by the answer found in the link I stated lines above.

Thanks!

1 Answers
Related