std::线程错误C2893在VS2015
std::thread Error C2893 in VS2015
// C2893.cpp
// OK in VS2013, Error in VS2015
// compile with: /EHsc
#include <thread>
//
template <typename T_app>
struct instance
{
void load() {;}
};
//
template <typename T_app>
struct scene
{
T_app *p_app;
void thread_load() {
std::thread(&instance<T_app>::load, std::ref(p_app->app_inst) ).detach();
}
};
//
struct app
{
instance<app> app_inst;
scene<app> app_scene;
};
//
int main() {
app my_app;
my_app.app_scene.p_app = &my_app;
// OK in VS2013, Error in VS2015
my_app.app_scene.thread_load();
return 0;
}
你好,我刚刚更新到VS2015, VS2013中的代码是可以的,如何纠正thread_load()
的错误?我阅读了Visual c++ 2015中的突破性变化,它必须是非类型模板参数问题,但我找不到正确的方法。谢谢。
错误在这里std::ref(p_app->app_inst)
。在这种情况下,std::thread
的第二个参数应该是instance*
,但p_app->app_inst
只是instance
类。
所以答案是std::thread(&instance<T_app>::load, &p_app->app_inst ).detach();
没有任何lambda函数
相关文章:
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 从VS 2015更新3更新到VS2015更新3 d后浮点计算行为不同的原因
- 使用 VS2015 在 Windows 10 上构建 Fortran .lib x64 位并将其链接到 C++
- VS2015 预处理器定义与点
- VS2015 中的 VC++ 目录
- VS2015 未链接用户32.lib
- VS2015/VC++ 在新类模板中禁用默认 #include "stdafx.h"
- 获取 c++ mfc vs2015 中弹出资源菜单项的 id
- c++11:在VS2015中分配全局STL "map<string, string>" initializer_list崩溃
- 如何在VS2015中重新定位VS2017解决方案?
- 暂时将C++项目(VS2015)移至Android操作系统.编译器选项?
- 在VS2015中访问类成员时运行时错误,但在Linux上未访问时出错
- 为什么在VS2015中模板相关的嵌套类型名称中不需要typename关键字?
- 精度::system_clock::现在在VS2015中
- 在VS2015中访问std::any
- VS2015中内置的程序的发布版本与Qt运行然后关闭没有错误?
- 如果使用低于 VS2015 的 vc++ 编译器版本编译,则 DLL 中的访问冲突
- 在Windows中构建GSL(GNU科学库)以与VS2015一起使用
- VS2015 中的英特尔实感 SDK 编程
- std::线程错误C2893在VS2015