I want to create a thread with no function arguments but I keep getting errors that are seriously bugging me because I cant get something super simple to work right
Heres my code:
#include<stdio.h>
#include<array>
#include<pthread.h>
#include<fstream>
#include<string>
void *showart(NULL);
int main(int argc, char** argv){
pthread_t thread1;
pthread_create( &thread1, NULL, showart, NULL);
getchar();
return 0;
}
void *showart(NULL)
{
std::string text;
std::ifstream ifs("ascii");
while(!ifs.eof())
{
std::getline(ifs,text);
printf(text.c_str());
}
}
It gives the error:
main.cpp:11:50: error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’ [-fpermissive]
Your function has to match the pthread one. Meaning it needs to take and return a void*
. Use void* showart(void*);
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With