gpt4 book ai didi

c++ - cpp 中的线程给出错误

转载 作者:行者123 更新时间:2023-11-30 02:26:15 27 4
gpt4 key购买 nike

int main()
{
std::thread t1(processVideo, "video1.mp4");
std::thread t2(processVideo, "video1.mp4");
// Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
t1.join();
t2.join();
destroyAllWindows();
return EXIT_SUCCESS;
}
void processVideo(char* videoFilename) {
//process the video file
}

每当我运行代码时,我都会收到以下错误:

1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(240): error C2672: 'std::invoke': no matching overloaded function found

1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(240): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'

1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(240): note: With the following template arguments:

1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(240): note: '_Callable=void (__cdecl *)(char *)'

1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(240): note: '_Types={const char *}'

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我尝试添加

std::thread t1(processVideo,this, "video1.mp4");

但它在编译时给我错误。

这只能在非静态成员函数中使用。

最佳答案

函数 void processVideo(char* videoFilename) 采用非常量 char*

字符串"video1.mp4"是一个const char*,与函数不兼容。

错误消息实际上表明了这一点,但是很难见树不见林。

关于c++ - cpp 中的线程给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43086876/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com