Create a thread over a templated member function

  c++, monitor, multithreading, templates

I have this templated member "function" which arguments are an object instance and a member function of this object (like a wrapper):

class Monitor
{
    Monitor();
    ~Monitor();
    
    template <typename O, typename F>
    void (O object, F function)
    {
        object.function();
    }
}

If we have this class:

class Object
{
     Object();
     ~Object();

     function()
     {
          std::cout << "Do something" << std::endl;
     };
}

The call to this function will be like this:

int main()
{
    Monitor monitor;
    Object object;
    
    monitor.waitData(object, function);

    return 0;
};

Now this is the question. If I want to call a thread which works over the member function "waitData", how should it be written?

int main()
{
    Monitor monitor;
    Object object;
    
    // std::thread threadWait(monitor.waitData(object, function)) -> Obviously gets an error
    std::thread threadWait(???????);

    return 0;
};

Thanks in advance.

Source: Windows Questions C++

LEAVE A COMMENT