Feb 27, 2021 at 2:11pm UTC
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
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);
Last edited on Feb 27, 2021 at 2:12pm UTC
Feb 27, 2021 at 4:57pm UTC
hi Salem c !
cMain::self *p = reinterpret_cast<cMain*>(arg);
error : class cMain has no member self
I corrected it
cMain *p = reinterpret_cast<cMain*>(arg);
it shows an error
'int pthread_create(pthread_t *,const pthread_attr_t *,void *(__cdecl *)(void *),void *)': cannot convert argument 3 from 'void (__cdecl *)(void *)' to 'void *(__cdecl *)(void *)'
Last edited on Feb 27, 2021 at 4:58pm UTC
Feb 28, 2021 at 6:34am UTC
Oops - Runner still needs to return void*
Last edited on Feb 28, 2021 at 6:34am UTC