I might be a little dense but cannot understand what below lines do?
class background_task
{
public:
void operator()() const
{
do_something();
do_something_else();
}
};
background_task f;
std::thread my_thread(f);
I realize a thread (named
my_thread
) is created which calls objectf
of classbackground_task
but when is the functionoperator()
in classbackground_task
actually called?Why is overloading of the function operator required?
I understand this is C++ 101 or very basic, but I still cannot grasp it, so which books should I refer to in order to learn more about such topics of C++.