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
  • @WilliamCustode Only with static void partialMatch(int i); Commented May 29, 2014 at 15:12

1 Answer 1

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(); } 
Sign up to request clarification or add additional context in comments.

3 Comments

Isn't that the same as following the advice in the first error code? as I said, when I do that, the second error stays there. Wolud you know how to fix it?
@n0b0dy1 did you pass the pointer to this as well?
You mean like "t[i](&ThreadedMatcher::partialMatch, this,i);"? If that's it, yes I did.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.