c++ - pthread_create - invalid use of non-static member function -


this question has answer here:

i've been trying learn how use threads, , i'm getting stuck on creating one. i'm having thread created in class constructor this...

beacon::beacon() {     pthread_create(&send_thread,null, send, null); } 

the send function isn't doing yet, here's looks like.

void beacon::send(void *arg){     //do stuff } 

everytime run code invalid use of non-static member funciton error. i've tried using &send, , didn't work. had last null parameter set this, didn't work. i've been looking @ other example code try , mimmick it, nothing seems work. doing wrong?

if can't use std::thread recommend create static member function wrap actual function, , pass this argument function.

something like

class beacon {     ...      static void* send_wrapper(void* object)     {         reinterpret_cast<beacon*>(object)->send();         return 0;     } }; 

then create thread like

pthread_create(&send_thread, null, &beacon::send_wrapper, this); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -