T :: *在模板的参数是什么意思? [英] What does T::* mean in template's parameters?
本文介绍了T :: *在模板的参数是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按照这里撰写的文章:
我遇到了这个代码(为了清晰起见,缩写和改变了):
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*/) { }
};
因此
std::string (C::*)()
任何人都可以向我解释 C :: *
部分?这是一个函数指针,返回 std :: string
但还有什么?
Can anyone explain me the C::*
part? That is a function pointer that returns std::string
but what more?
推荐答案
成员函数指向C类中返回 std :: string
的成员的成员函数指针。
A member function pointer to a member in class C that returns a std::string
.
检查 isocpp.org 了解有关成员函数指针的更多信息。
Check isocpp.org for more info on pointers to member functions.
这篇关于T :: *在模板的参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文