[英]c++ error C2893: Failed to specialize function template
I'm trying to run this but I keep receiving an error. 我正在尝试运行此程序,但我一直收到错误消息。
#include <iostream>
#include <thread>
using namespace std;
void primeNumbers( int num, int prime )
{
cout << "The prime numbers equal to or below " << num << " are: " << endl;
for ( int i = 1; i <= num; i++ )
{
prime = 0;
for( int j = 2;j <= i/2; j++ )
{
if( i % j ==0 )
{
prime++;
break;
}
}
if ( prime == 0 && i != 1 )
cout << i << endl;
}
}
int main()
{
int num;
int prime = 0;
cout << "Enter a positive integer: ";
cin >> num;
std::thread primeN( primeNumbers );
primeN.join( );
system("pause");
return 0;
}
I've copied everything from the output window. 我已经从输出窗口复制了所有内容。
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): 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(238): note: With the following template arguments:
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): note: '_Callable=void (__cdecl *)(int,int)'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): note: '_Types={}'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad<_Target>::_Execute<0>(std::tuple<void (__cdecl *)(int,int)> &,std::integer_sequence<_Ty,0>)' being compiled
1> with
1> [
1> _Target=std::unique_ptr<std::tuple<void (__cdecl *)(int,int)>,std::default_delete<std::tuple<void (__cdecl *)(int,int)>>>,
1> _Ty=size_t
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad<_Target>::_Execute<0>(std::tuple<void (__cdecl *)(int,int)> &,std::integer_sequence<_Ty,0>)' being compiled
1> with
1> [
1> _Target=std::unique_ptr<std::tuple<void (__cdecl *)(int,int)>,std::default_delete<std::tuple<void (__cdecl *)(int,int)>>>,
1> _Ty=size_t
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(242): note: while compiling class template member function 'void std::_LaunchPad<_Target>::_Run(std::_LaunchPad<_Target> *) noexcept'
1> with
1> [
1> _Target=std::unique_ptr<std::tuple<void (__cdecl *)(int,int)>,std::default_delete<std::tuple<void (__cdecl *)(int,int)>>>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(230): note: see reference to function template instantiation 'void std::_LaunchPad<_Target>::_Run(std::_LaunchPad<_Target> *) noexcept' being compiled
1> with
1> [
1> _Target=std::unique_ptr<std::tuple<void (__cdecl *)(int,int)>,std::default_delete<std::tuple<void (__cdecl *)(int,int)>>>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(256): note: see reference to class template instantiation 'std::_LaunchPad<_Target>' being compiled
1> with
1> [
1> _Target=std::unique_ptr<std::tuple<void (__cdecl *)(int,int)>,std::default_delete<std::tuple<void (__cdecl *)(int,int)>>>
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\thread(52): note: see reference to function template instantiation 'void std::_Launch<std::unique_ptr<std::tuple<void (__cdecl *)(int,int)>,std::default_delete<std::tuple<void (__cdecl *)(int,int)>>>>(_Thrd_t *,_Target &&)' being compiled
1> with
1> [
1> _Target=std::unique_ptr<std::tuple<void (__cdecl *)(int,int)>,std::default_delete<std::tuple<void (__cdecl *)(int,int)>>>
1> ]
1> c:\users\andre\documents\school\csci\prime\prime\testprime.cpp(34): note: see reference to function template instantiation 'std::thread::thread<void(__cdecl &)(int,int),,void>(_Fn)' being compiled
1> with
1> [
1> _Fn=void (__cdecl &)(int,int)
1> ]
I don't know much about multithreading as I just started learning about it yesterday. 我对多线程了解不多,因为我昨天才开始学习它。 So if I did something completely wrong please let me know.
因此,如果我做的事情完全错误,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.