0

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);
}
b3hn4m
  • 75
  • 4
  • _"the class name with the overloaded parentheses `HelloWorld()`"_ is a call to the implicitly defined default-constructor of `HelloWorld`. The duplicate should explain the rest. – Lukas-T Sep 24 '21 at 05:11
  • Possibly duplicate of "[What is the meaning of, returning value being a class name followed by a pair of empty parentheses?](https://stackoverflow.com/q/57025272/90527)" – outis Oct 06 '21 at 10:31

0 Answers0