Sumeet Batra
Sumeet Batra

Reputation: 357

Android NDK Thread invalid use of non-static member function

I need to use threads in my android application because I am doing image processing w/ native opencv. Here is my code:

void Detector::processBinary(Mat &binary) {
    //do stuff
}

void Detector::Detect() {
   ...
   thread t1(processBinary, binary);
   t1.join();
}

However, I get the error "invalid use of non-static member function" from thread t1(processBinary, binary) whenever I try to run the app. This line, however, works perfectly in visual studio. Can anyone help me with this? Thanks in advance!

Upvotes: 1

Views: 180

Answers (1)

Sergio
Sergio

Reputation: 8209

You use member function, that needs this argument (it must be called on some object). There are two alternatives:

Use static class function (or non-class function at all):

void processBinary(Mat &binary) {
    //do stuff
}

void Detector::Detect() {
   ...
   thread t1(processBinary, binary);
   t1.join();
}

Or pass proper arguments if we want utilize member function:

void Detector::processBinary(Mat &binary) {
    //do stuff
}

void Detector::Detect() {
   ...
   thread t1(&Detector::processBinary, *this, binary);
   t1.join();
}

Upvotes: 1

Related Questions