I'm studying threads in c++. I'm using the CreateThread()
function from windows.h
library:
#include <windows.h>
#include <iostream>
#include <unistd.h>
DWORD WINAPI ThreadFunc(void* data, std::string message) {
std::cout<<message;
return 0;
}
int main() {
std::string saluti="hi";
HANDLE thread = CreateThread(NULL, 0, ThreadFunc, &saluti, 0, NULL);
sleep(5);
}
The error:
error: invalid conversion from 'DWORD (__attribute__((__stdcall__)) *)(void*, std::__cxx11::string) {aka long unsigned int (__attribute__((__stdcall__)) *)(void*, std::__cxx11::basic_string<char>)}' to 'LPTHREAD_START_ROUTINE {aka long unsigned int (__attribute__((__stdcall__)) *)(void*)}' [-fpermissive]
HANDLE thread = CreateThread(NULL, 0, ThreadFunc, &saluti, 0, NULL);
^
how can i pass a std::string
to a thread function?