Possible duplicate:
Pthread function from class
I have this code that I cannot compile due to the pthread_create line:
void* gtk_functor::_threaded_run(void* win) { Gtk::Window* w = static_cast<Gtk::Window*>(win); Gtk::Main::run(*w); delete w; } void gtk_functor::operator ()(Gtk::Window& win, bool threaded) { if (threaded) { pthread_t t_num; pthread_create(&t_num, NULL, (void* (*)(void*))>k_functor::_threaded_run, static_cast<void*>(&win)); } else { Gtk::Main::run(win); } }
This gcc line is:
g++ -o main 'pkg-config --cflags --libs sqlite3 gtkmm-3.0' -lpthread main.cpp
does a compilation at the end with this output:
code/ui.cpp: In member function 'void ui::gtk_functor::operator()(Gtk::Window&, bool)': code/ui.cpp:45:65: warning: converting from 'void* (ui::gtk_functor::*)(void*)' to 'void* (*)(void*)' [-Wpmf-conversions]
and apparently the code is not working correctly, I get a sementation fault when if (threaded) goes up.
I know it with cast, but I don't know the correct form for passing a member function to pthread_create. Any suggestions?
c ++ pthreads g ++ member-functions
Haix64 Jul 17 '12 at 18:33 2012-07-17 18:33
source share