开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜