In the following example, I understand how boost signal and functor work, however, my question is about how the class name with the overloaded parentheses HelloWorld()
is used. As HelloWorld
is a functor, the created object should actually use the operator()
, not the class (functor) name. What is this practice called and what is its common application?
#include <boost/signals2.hpp>
#include <iostream>
struct HelloWorld
{
void operator()(int val_) const
{
std::cout << "Hello, World!" << val_ << std::endl;
}
};
int main()
{
boost::signals2::signal<void (int)> sig;
HelloWorld hello;
hello(6);
sig.connect(HelloWorld());
sig(5);
}