[英]Error: 'Failed to specialize function template' C2893 'std::invoke'
I am writing an MFC program in Visual Studio 2013 and i keep getting the two following errors 我正在Visual Studio 2013中编写一个MFC程序,我不断收到以下两个错误
Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
and 和
Error C2672 'std::invoke': no matching overloaded function found
The error is related to file xthread line 238 该错误与文件xthread行238有关
I am fairly new at c++/MFC and I am trying to write a function that will run in the background to the system time. 我在c ++ / MFC上相当新,我正在尝试编写一个将在后台运行到系统时间的函数。
This is the code i am using: 这是我正在使用的代码:
void task1(ExperimentTab& dlg)
{
while (true)
{
CString showtime = CTime::GetCurrentTime().Format("%H:%M:%S");
int x = dlg.m_showTime.GetWindowTextLengthA();
dlg.m_showTime.SetWindowTextA(_T(""));
dlg.m_showTime.ReplaceSel(showtime, 0);
}
}
void mainThread()
{
std::thread t1(task1);
t1.join();
}
This is then being called on a button press to start the time, but the same button is used to also stop the time. 然后在按下按钮时调用此按钮以开始时间,但同样的按钮也用于停止时间。
Function task1
takes single argument (used as thread body), yet you pass none in t1
constructor. 函数
task1
采用单个参数(用作线程体),但在t1
构造函数中没有传递。 Compiler fails to create std::invoke
calling task1
function without method argument. 编译器无法在没有方法参数的情况下创建
std::invoke
调用task1
函数。
To fix it call constructor like that: std::thread t1(task1, std::ref(dlg));
修复它的调用构造函数:
std::thread t1(task1, std::ref(dlg));
, where dlg
is ExperimentTab
. ,其中
dlg
是ExperimentTab
。 std::ref
ensures that dlg
will be passed to thread via reference. std::ref
确保dlg
将通过引用传递给线程。
BTW: updating MFC component from other thread might lead to some data races. BTW:从其他线程更新MFC组件可能会导致一些数据争用。 Also -
while(true)
thread will consume 100% of CPU by multiple updates per second of timer with second resolution. 此外 -
while(true)
线程将通过具有第二分辨率的每秒定时器的多次更新消耗100%的CPU。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.