问题描述
限时送ChatGPT账号..我正在研究 Boost 中 is_class
模板的实现,但遇到了一些我无法轻易破译的语法.
I was looking at the implementation of the is_class
template in Boost, and ran into some syntax I can't easily decipher.
template <class U> static ::boost::type_traits::yes_type is_class_tester(void(U::*)(void));
template <class U> static ::boost::type_traits::no_type is_class_tester(...);
我如何解释上面的 void(U::*)(void)
?我熟悉 C,所以它看起来有点类似于 void(*)(void)
,但我不明白 U::
如何修改指针.有人可以帮忙吗?
How do I interpret void(U::*)(void)
above? I'm familiar with C, so it appears somewhat analogous to void(*)(void)
, but I don't understand how U::
modifies the pointer. Can anyone help?
谢谢
推荐答案
*
表示一个指针,因为你可以通过写*p
来访问它的内容.U::*
表示指向U
类成员的指针.您可以通过编写 u.*p
或 pu->*p
来访问其内容(其中 u
是 U
).
*
indicates a pointer, because you can access its contents by writing *p
. U::*
indicates a pointer to a member of class U
. You can access its contents by writing u.*p
or pu->*p
(where u
is an instance of U
).
因此,在您的示例中,void (U::*)(void)
是指向 U
成员的指针,即一个不带参数且不返回值的函数.
So, in your example, void (U::*)(void)
is a pointer to a member of U
that is a function taking no arguments and returning no value.
示例:
class C { void foo() {} };
typedef void (C::*c_func_ptr)(void);
c_func_ptr myPointer = &C::foo;
这篇关于void(U::*)(void) 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论