我想创建一个没有函数参数的线程,但我一直收到严重困扰我的错误,因为我无法让一些 super 简单的东西正常工作
这是我的代码:
#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());
}
}
它给出了错误:
main.cpp:11:50: error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’ [-fpermissive]
最佳答案
您的函数必须与 pthread 相匹配。这意味着它需要获取并返回一个 void*
。请改用 void* showart(void*);
。
关于c++ - pthread_create 没有参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33193333/