我有以下程序:
# include <stdio.h>
# include <thread>
class foo
{
public:
//intentional __stdcall, breaks compilation
virtual void __stdcall printOut(const char* str)
{
printf("%s", str);
}
};
foo bar;
int main(void)
{
std::thread(&foo::printOut, &bar, "Printing output");
return 0;
}
尝试使用msvc 11.0(VS2012)编译上述代码会引发以下错误:
error C2064: term does not evaluate to a function taking 2 arguments
...\functional(1152) : while compiling class template member function 'std::_Do_call_ret<_Forced,_Ret,_Funx,_Btuple,_Ftuple>::type std::_Bind<false,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>::operator ()(void)'
with
[
_Forced=false,
_Ret=void,
_Funx=void (__stdcall foo::* )(const char *),
_Btuple=std::tuple<foo *,const char *>,
_Ftuple=std::tuple<>,
_Fun=void (__stdcall foo::* )(const char *),
_V0_t=foo *,
_V1_t=const char (&)[13],
_V2_t=std::_Nil,
_V3_t=std::_Nil,
_V4_t=std::_Nil,
_V5_t=std::_Nil,
<unnamed-symbol>=std::_Nil
]
.../xthread(195) : see reference to function template instantiation 'std::_Do_call_ret<_Forced,_Ret,_Funx,_Btuple,_Ftuple>::type std::_Bind<false,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>::operator ()(void)' being compiled
with
[
_Forced=false,
_Ret=void,
_Funx=void (__stdcall foo::* )(const char *),
_Btuple=std::tuple<foo *,const char *>,
_Ftuple=std::tuple<>,
_Fun=void (__stdcall foo::* )(const char *),
_V0_t=foo *,
_V1_t=const char (&)[13],
_V2_t=std::_Nil,
_V3_t=std::_Nil,
_V4_t=std::_Nil,
_V5_t=std::_Nil,
<unnamed-symbol>=std::_Nil
]
...\thread(52) : see reference to class template instantiation 'std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>' being compiled
with
[
_Forced=false,
_Ret=void,
_Fun=void (__stdcall foo::* )(const char *),
_V0_t=foo *,
_V1_t=const char (&)[13],
_V2_t=std::_Nil,
_V3_t=std::_Nil,
_V4_t=std::_Nil,
_V5_t=std::_Nil,
<unnamed-symbol>=std::_Nil
]
main.cpp(24) : see reference to function template instantiation 'std::thread::thread<void(__stdcall foo::* )(const char *),foo*,const char(&)[13]>(_Fn,_V0_t &&,_V1_t)' being compiled
with
[
_Fn=void (__stdcall foo::* )(const char *),
_V0_t=foo *,
_V1_t=const char (&)[13]
]
没有__stdcall,这个程序构建正常。拥有或没有调用约定IMO应该对std :: thread无关紧要,但它似乎影响了这个方法的解释方式。编译器似乎很难看到printOut(const char*)
符合定义 - (foo::* )(const char *)
。
这是msvc 11.0的问题还是我错过了什么?