pthread function from a class

前端 未结 9 1069
天命终不由人
天命终不由人 2020-11-22 01:00

Let\'s say I have a class such as

class c { 
    // ...
    void *print(void *){ cout << \"Hello\"; }
}

And then I have a vector of c

9条回答
  •  广开言路
    2020-11-22 01:26

    My guess would be this is b/c its getting mangled up a bit by C++ b/c your sending it a C++ pointer, not a C function pointer. There is a difference apparently. Try doing a

    (void)(*p)(void) = ((void) *(void)) &c[0].print; //(check my syntax on that cast)
    

    and then sending p.

    I've done what your doing with a member function also, but i did it in the class that was using it, and with a static function - which i think made the difference.

提交回复
热议问题