我正在尝试编写一个模板,将模板作为非类型参数传递给静态成员函数:
#include <iostream>
using namespace std;
class C {
public:
static void method()
{
cout << "C::method" << endl;
}
};
typedef void (C::*pMethod)();
template<typename T, pMethod>
void callingFunction()
{
T c;
pMethod aPointerToMember = &T::method;
(c.*aPointerToMember)();
}
int main()
{
callingFunction<C, &C::method>();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是在main中调用函数时总是会出错:
error: no matching function for call to 'callingFunction()' // mingw
Run Code Online (Sandbox Code Playgroud)
如果成员函数不是静态的,它可以工作,我怎样才能使它与静态函数一起工作?
谢谢.
谢谢
| 归档时间: |
|
| 查看次数: |
823 次 |
| 最近记录: |