简体   繁体   English

错误:'无法专门化功能模板'C2893'std :: invoke'

[英]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 . ,其中dlgExperimentTab 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.

相关问题 错误C2893无法专门化函数模板&#39;unknown-type std :: invoke(_Callable &amp;&amp;,_ Types &amp;&amp; ...)&#39; - Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&…)' 错误C2893:无法专门化函数模板&#39;unknown-type std :: invoke(_Callable &amp;&amp;,_ Types &amp;&amp; ...)noexcept( <expr> )” - error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&…) noexcept(<expr>)' 错误C2893:无法专门化功能模板 - error C2893: Failed to specialize function template 错误C2893:无法使用CTPL专门化功能模板 - error C2893: Failed to specialize function template with CTPL C ++错误C2893:无法专门化功能模板 - c++ error C2893: Failed to specialize function template 错误C2893:无法专门化功能模板C ++ - error C2893: Failed to specialize function template C++ 错误C2893:无法专门化功能模板&#39;unknown-type std :: less <void> :: operator()(_ Ty1 &amp;&amp;,_ Ty2 &amp;&amp;)const&#39; - error C2893: Failed to specialize function template 'unknown-type std::less<void>::operator ()(_Ty1 &&,_Ty2 &&) const' 错误C2893:无法专门化函数模板VC ++ 2012 - Error C2893: Failed to specialize function template VC++ 2012 Visual C ++ 2015 std :: function与C2893 - Visual C++ 2015 std::function vs C2893 VS2015中的std :: thread错误C2893 - std::thread Error C2893 in VS2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM