我有这个问题:
template <void (*F)(int)> struct FunctionWrapper // This compiles and works
{
static void call_it()
{
F(0);
}
};
class MyClass
{
public:
static void callMe(int k)
{
}
};
template <void (MyClass::*F)(int)> struct FunctionWrapper // Error - F incompatible with declaration
{
static void call_it()
{
MyClass::F(0);
}
};
为什么我可以使用函数指针(编译时常量),但不能使用类成员(甚至静态)指针?
最佳答案
静态函数与普通函数具有相同的类型签名;它并不是真正的成员函数。
关于c++ - 模板函数参数和模板成员函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15176060/