C++ 将另一个类成员函数作为线程调用时发出警告消息
我有一个类,它包含多个方法。我的要求是调用另一个成员函数中的一个作为线程C++ 将另一个类成员函数作为线程调用时发出警告消息,c++,multithreading,c++17,stdthread,C++,Multithreading,C++17,Stdthread,我有一个类,它包含多个方法。我的要求是调用另一个成员函数中的一个作为线程 Class ApplicationManager { .... .... void method(); void test(std::string arg1, std::string& arg2); }; void ApplicationManager::method() { std::string arg, arg2; .... .... std::thread(
Class ApplicationManager
{
....
....
void method();
void test(std::string arg1, std::string& arg2);
};
void ApplicationManager::method()
{
std::string arg, arg2;
....
....
std::thread(&ApplicationManager::test, this, arg, arg2);
}
当我编译上面的代码时,我得到了下面的警告消息。因为它太大了,我无法理解它想说什么。复制了下面的警告消息
C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\type_traits16707566:警告C4239:使用了非标准扩展名:“参数”:从“_Ty”转换为“std::string&”
具有
[
_Ty=std::基本字符串,std::分配器>
]
C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\type\u traits16707566:注意:非常量引用只能绑定到左值
C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\type_traits16707566:注意:请参阅函数模板实例化“void std::_Invoker_pmf_pointer::_Call,std::basic_string,std::allocator>>_Decayed,_Ty1&,std::basic_string,std::allocator>&,std::basic_string,正在编译std::allocator>&&noexceptfalse
具有
[
_Ty=void\uu cdecl应用程序管理器::*std::string,std::string&,
_Decaded=void\uu cdecl应用程序管理器::*标准::字符串,标准::字符串&,
_Ty1=应用程序管理器*
]
C:\Program Files x86\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\thr/xthread237:
注意:请参阅函数模板实例化“void”的参考
std::invoke,std::allocator>,std::basic\u字符串,std::allocator>>\u可调用
&&,应用程序管理器
&&,std::basic_字符串,std::分配器>
&&,std::basic_字符串,std::分配器>
&&正在编译“noexceptfalse”
具有
[
_Callable=void\uu cdecl ApplicationManager::std::string,std::string&
]C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\thr/xthread246:
注意:请参阅函数模板实例化“void”的参考
std::_启动板::_Executestd::tuple,std::allocator>,std::basic_字符串,std::allocator>>&正在编译std::integer_序列
具有
[
_Target=std::unique\u ptr,std::allocator>,std::basic\u字符串,std::allocator>>,std::default\u delete,std::allocator>,std::basic\u字符串,std::allocator>>,
_Ty=尺寸
]C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\thr/xthread245:
注意:请参阅函数模板实例化“void”的参考
std::_启动板::_Executestd::tuple,std::allocator>,std::basic_字符串,std::allocator>>&正在编译std::integer_序列
具有
[
_Target=std::unique\u ptr,std::allocator>,std::basic\u字符串,std::allocator>>,std::default\u delete,std::allocator>,std::basic\u字符串,std::allocator>>,
_Ty=尺寸
]C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\thr/xthread242:
注意:编译类模板成员函数“void”时
标准::_启动板::_运行标准::_启动板*无例外'
具有
[
_Target=std::unique\u ptr,std::allocator>,std::basic\u字符串,std::allocator>>,std::default\u delete,std::allocator>,std::basic\u字符串,std::allocator>>>>
]C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\thr/xthread230:
注意:请参阅函数模板实例化“void”的参考
标准::_启动板::_运行标准::_启动板*无例外'
正在编辑
具有
[
_Target=std::unique\u ptr,std::allocator>,std::basic\u字符串,std::allocator>>,std::default\u delete,std::allocator>,std::basic\u字符串,std::allocator>>>>
]C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\thr/xthread257:
注意:请参阅类模板实例化的参考
正在编译“std::_LaunchPad”
具有
[
_Target=std::unique\u ptr,std::allocator>,std::basic\u字符串,std::allocator>>,std::default\u delete,std::allocator>,std::basic\u字符串,std::allocator>>>>
]C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\thread46:
注意:请参阅函数模板实例化“void”的参考
std::_启动,std::分配器>,std::基本字符串,std::分配器>>,std::默认值\u删除>>\u Thrd\t
*,_正在编译目标&&
具有
[
_Ty=std::tuple,std::allocator>,std::basic_字符串,std::allocator>>,
_Target=std::unique\u ptr,std::allocator>,std::basic\u字符串,std::allocator>>,std::default\u delete,std::allocator>,std::basic\u字符串,std::allocator>>>>
]....\Sources\ApplicationManager.cpp3856:注意:请参阅函数模板实例化的参考
'std::thread:
:螺纹
&&,ApplicationManager&,正在编译std::string&,std::string&'
具有
[
_Fn=void\uu cdecl应用程序管理器::std::string,std::string&
]C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\filesystem2392:
注意:请参阅类模板实例化的参考
'std::chrono::time\u point'
正在编译C:\Program Files x86\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\type\u traits616:
注意:请参阅类模板实例化的参考
“std::basic_string_view>”正在
编译的C:\Program Files x86\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\xstring2124:
注意:请参阅类模板实例化的参考
“std::是否可转换>>”正在
汇编
具有
[
_StringViewIsh=常量wchar\t*
]C:\Program Files x86\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\xstring2122:
注:参见变量模板“const bool”的参考
正在编译的C:\Program Files
x86\Microsoft Visual
Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\xstring2281:
注意:请参阅别名模板实例化的参考
'std::basic_string,std::allocator>:::_是_string_view_ish'
正在编辑
具有
[
_StringViewIsh=常量wchar\t*
]*
你的职能
test(std::string arg1, std::string& arg2);
将引用作为第二个参数,但此处
std::thread(&ApplicationManager::test, this, arg, arg2);
它采用的是一个值而不是引用,因此您必须将其修改为
std::thread(&ApplicationManager::test, this, arg, std::ref(arg2));
在引用包装器对象中包装对变量的引用
请注意,您发布的编译器消息是特定于MVC编译器的,但您的代码在使用gcc或clang进行编辑之前不会编译,正如cigien所提到的。无法复制:请编辑您的帖子以包含一个。@aschepler我编辑了我的帖子。我的第二个参数是一个引用。@cigien你能准确地告诉我这个问题吗:这似乎是一个msvc扩展。当成员函数参数是左值引用时,gcc和clang甚至不编译。