0
我有MSVC2013更新4使用了以下類:爲什麼這個模板不能編譯?
template <typename T>
class MyFunction;
template<typename R, class... Ts>
class MyFunction < R(Ts...) >
{
public:
using func_type = R(*)(Ts...);
MyFunction(func_type f)
: m_func(f)
{
}
R operator()(Ts ... args)
{
return m_func(args...);
}
private:
func_type m_func;
};
如果我使用它像這樣:
MyFunction<int (int)> f1(nullptr);
MyFunction<int __cdecl(int)> f2(nullptr);
MyFunction<int __stdcall(int)> f3(nullptr);
爲什麼F3編譯失敗? (考慮到__cdecl的作品!)。
error C2079: 'f3' uses undefined class 'MyFunction<int (int)>'
error C2440: 'initializing' : cannot convert from 'nullptr' to 'int'
'nullptr = NULL'。想想看。 –
構造函數需要一個func_type,這是一個函數指針,因此nullptr很好? – paulm
我懷疑'R(Ts ...)'隱含地是'R __cdecl(Ts ...)',所以部分特化不匹配'int __stdcall(int)'。 –