我想创建一个没有函数参数的线程,但我不断收到严重困扰我的错误,因为我无法让一些超级简单的东西正常工作
这是我的代码:
#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*
.
Use void* showart(void*);
反而。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)