Functionality of void operator()()

前端 未结 4 692
一生所求
一生所求 2021-02-01 05:11

I am confused about the functionality of void operator()().

Could you tell me about that, for instance:

class background_task
{
public:

            


        
4条回答
  •  误落风尘
    2021-02-01 05:43

    The first () is the name of the operator - it's the operator that is invoked when you use () on the object. The second () is for the parameters, of which there are none.

    Here's an example of how you would use it:

    background_task task;
    task();  // calls background_task::operator()
    

提交回复
热议问题