[英]What does T::* mean in template's parameters?
Following the article written in here : 在这里写的文章之后:
I came across this code (shortened and changed for clarity): 我遇到了以下代码(为清楚起见,对其进行了缩短和更改):
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*/) { }
};
So this 所以这
std::string (C::*)()
caught my attention. 引起了我的注意。
Can anyone explain me the C::*
part? 谁能解释
C::*
部分? That is a function pointer that returns std::string
but what more? 那是一个返回
std::string
的函数指针,还有什么呢?
A member function pointer to a member in class C that returns a std::string
. 指向类C中的成员的成员函数指针,该成员返回
std::string
。
Check isocpp.org for more info on pointers to member functions. 请访问isocpp.org ,以获取有关成员函数指针的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.