Templates non-type parameters to a static member function
I'm trying to write a template that takes a template to a non-type parameter to a static member function:
#include <iostream>
using namespace std;
class C {
public:
static void method()
{
cout << "C::method" << endl;
}
};
typedef void (C::*pMethod)();
template<type开发者_StackOverflow社区name T, pMethod>
void callingFunction()
{
T c;
pMethod aPointerToMember = &T::method;
(c.*aPointerToMember)();
}
int main()
{
callingFunction<C, &C::method>();
return 0;
}
But I always get error when calling the function in main:
error: no matching function for call to 'callingFunction()' // mingw
If The member function is not static it works, how can I make it work with static function ?
Thanks.
Thank you
For a static member function, change your typedef to typedef void (*pMethod)();
- as if it was a free function.
精彩评论