0

I'm trying to make a class with a method that calls other method (that is in the same class) multiple times using multithreading. The code is something like this:

#include <iostream>
#include <thread> 
using namespace std;

class ThreadedMatcher
{
    float Match()
    {
        thread t[5];
        //5 is just as an aleatory number
        //The error doesn't change if I use a pointer (like thread *t;)
        for (int i = 0; i < num_jobs; i++)
        {
            t[i](partialMatch,i);
        }
    }

    void partialMatch(int i){
        //Whathever I put in here doesn't change the error
    }
}

(this code is written in "ThreadedMatcher.h")

When I compile this, the next two errors appear:

error c3867: 'ThreadedMatcher::partialMatch': function call missing argument list; use '&ThreadedMatcher::partialMatch' to create a pointer to member

error c2064: term does not evaluate to a function taking 2 arguments

(these two errors refers to the part inside the for bucle)

If I follow the advise in the first error, the second error stays there anyway.

Could anyone tell me how to solve this? I'm using visual studio 2012 (c++11), in windows 8.

Thank you for any help you can provide.

PS: Sorry for my bad english, I did the best I could

1 Answers1

0

To reference a function in a class, you must reference the class in which the function resides.

change your thread execution to pass by reference.

This SO question

Explains it nicely

From that question

void Test::runMultiThread()
{
    std::thread t1(&Test::calculate, this,  0, 10);
    std::thread t2(&Test::calculate, this, 11, 20);
    t1.join();
    t2.join();
}
Community
  • 1
  • 1
Benjamin Trent
  • 7,378
  • 3
  • 31
  • 41