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)'。 –