错误:'Failed to specialize function template' C2893 'std::invoke'
Error: 'Failed to specialize function template' C2893 'std::invoke'
我正在Visual Studio 2013中编写MFC程序,并且不断收到以下两个错误
Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
和
Error C2672 'std::invoke': no matching overloaded function found
该错误与文件xthread第238行有关
我对c++/MFC还很陌生,我正在尝试编写一个在系统后台运行的函数。
这是我正在使用的代码:
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();
}
然后按下按钮开始计时,但同样的按钮也用于停止计时。
函数task1
只接受一个参数(用作线程体),但在t1
构造函数中不传递任何参数。编译器无法在没有方法参数的情况下创建调用task1
函数的std::invoke
。
要修复它,请调用类似的构造函数:std::thread t1(task1, std::ref(dlg));
,其中dlg
是ExperimentTab
。std::ref
确保dlg
将通过引用传递给线程。
BTW:从其他线程更新MFC组件可能会导致一些数据争用。此外,while(true)
线程将通过每秒多次更新秒分辨率的计时器来消耗100%的CPU。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 将对象移动到std::shared_ptr
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用一个考虑到std::map中键值的滚动或换行的键
- 错误 C2893 无法专门化函数模板'unknown-type std::invoke(_Callable &&,_Types &&...)'
- 错误:'Failed to specialize function template' C2893 'std::invoke'
- Visual C++ 2015 std::function vs C2893
- std::线程错误C2893在VS2015