void operator()(){/* work here */}As a pattern in c++ threading examples, but I could not read it. It was really hard to figure out, because "()()" is not a an indexable string. This means that not only can you not search for it online, it does not appear in the index of paper C++ reference manuals either.
I knew that this code is overloading the function operator, but the term "function operator" is almost never used to literally refer to the c++ function operator. So searching for combination of "overloading the function operator" was fruitless.
Finally, I found the Wikipedia page on STL, which included
"The STL includes classes that overload the function operator (operator()). Classes that do this are called functors or function objects. They are useful for keeping and retrieving state information in functions passed into other functions. Regular function pointers can also be used as functors."
This was enough of lead to find enough info.
A class that overloads the function operator ( a functor ) allows one to use instances of that class anywhere you would want to use a function. In particular, you can pass a functor instance to something, and that something can "run" that object. It is effectively similar to "Runnable" in Java.
No comments:
Post a Comment