static thread function access non-static class member in C++

Posted by user397390 on Stack Overflow See other posts from Stack Overflow or by user397390
Published on 2011-01-08T09:09:26Z Indexed on 2011/01/08 9:53 UTC
Read the original article Hit count: 157

Filed under:
Class Test{
    int value;
    static void* thread_func(void* args){
        value++;
    }
    void newthread(){
        pthread_create(&thread_func,...);
    }
}

I'm trying to create a thread in Class Test. Therefore compiler forces me to make thread_func static. However I cannot access the non-static member "value" anymore. It says:

invalid use of member 'Class::value' in static member function

Is there a way around it?

© Stack Overflow or respective owner

Related posts about c++