I want the Run function to run its own thread, but it shows an error, how to make it compatible with each other
Error : argument of type "void (cMain::)(void *arg)" is incompatible with parameter of type "void *(__cdecl *)(void *)"
cMain.h
#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>
using std::string;
class cMain
{
public:
cMain();
~cMain();
public:
wxListView *Listview1 = nullptr;
void *Run(void *arg);
int main();
};
cMain.cpp
void * cMain::Run(void *arg)
{
int i = 0;
while (true)
{
i += 1;
Listview1->SetItem(0, 0, std::to_string(i));
Sleep(200);
}
pthread_exit(NULL);
return 0;
}
int cMain::main()
{
pthread_t my_thread;
int ret;
ret = pthread_create(&my_thread, NULL, &Run, NULL);
if (ret != 0) {
MessageBox(NULL, L"Error: pthread_create() failed", L"AA", MB_OK);
exit(EXIT_FAILURE);
}
}
error code : ret = pthread_create(&my_thread, NULL, &Run, NULL);
c. In the title you havec++. You use C-specific linux thread interface -pthread_*. Your code is in C++. In C++ use C++ - usestd::thread. So you write in C or in C++?argument of type "void (cMain::)(void *arg)" is incompatible with parameter of type "void *(__cdecl *)(void *)"and research what is a function member and what is a pointer to member function and how to use it. You can't pass a pointer to class member function topthread. You have to passvoid(void*)function. - KamilCuk