T::* 在模板的参数中是什么意思?

Pat*_*ryk 1 c++ templates metaprogramming template-meta-programming type-deduction

按照这里写的文章:

我遇到了这个代码(为了清楚起见,缩短并更改了):

template <class T> struct hasSerialize
{
    // This helper struct permits us to check that serialize is truly a method.
    // The second argument must be of the type of the first.
    // For instance reallyHas<int, 10> would be substituted by reallyHas<int, int 10> and works!
    // reallyHas<int, &C::serialize> would be substituted by reallyHas<int, int &C::serialize> and fail!
    // Note: It only works with integral constants and pointers (so function pointers work).
    // In our case we check that &C::serialize has the same signature as the first argument!
    // reallyHas<std::string (C::*)(), &C::serialize> should be substituted by 
    // reallyHas<std::string (C::*)(), std::string (C::*)() &C::serialize> and work!
    template <typename U, U u> struct reallyHas;

    // We accept a pointer to our helper struct, in order to avoid to instantiate a real instance of this type.
    // std::string (C::*)() is function pointer declaration.
    template <typename C>
    static char&
    test(reallyHas<std::string (C::*)(), &C::serialize>* /*unused*/) { }
};
Run Code Online (Sandbox Code Playgroud)

所以这

std::string (C::*)()
Run Code Online (Sandbox Code Playgroud)

吸引了我的注意力。

谁能给我解释一下这C::*部分?那是一个返回的函数指针,std::string但还有什么?

i_a*_*orf 5

指向 C 类成员的成员函数指针,该成员返回std::string.

查看isocpp.org以获取有关成员函数指针的更多信息。