Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: invalid use of non-static member function #4

Open
hanito opened this issue Oct 22, 2015 · 2 comments
Open

error: invalid use of non-static member function #4

hanito opened this issue Oct 22, 2015 · 2 comments

Comments

@hanito
Copy link

hanito commented Oct 22, 2015

Hello,
I am trying to call a function call_from_thread_description from another function inside a class and I am getting the following error. I can't find the right to add a function to the pool.

Error: /home/hani/workspace/transform/Transform.cpp:127:104: error: invalid use of non-static member functiondr esults.push_back(thread_pool.push(Transform::call_from_thread_description, data[i], data[j], res));

void Transform::call_from_thread_description(const vector<string> & e1, const <string> & e2, <string>  & res)
{ 
//DO SOMETHING HERE
}
void Transform::computer_intersection()
{
    vector<string> res;
    int Num_Threads =  thread::hardware_concurrency();
    ctpl::thread_pool thread_pool(Num_Threads);
    for(int i = 0; i < data.size();i++)
    {
        data_sets tmp;
        for(int j = 0; j < data.size();j++)
        {
            results.push_back(thread_pool.push(call_from_thread_description, data[i], data[j], res));
            if(j % Num_Threads == 0 || j == data.size() -1)
            {
               results.clear();
            }
       }
  }
}
@VPaulV
Copy link

VPaulV commented Jul 7, 2016

Just use lambda function, like this:

results.push_back(thread_pool.push([&, this](int id){ call_from_thread_description(data[i], data[j], res)});

@MisterTea
Copy link

Can this use-case be added to the README and example.cpp? It's really useful to see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants