void(U::*)(void) 是什么意思? [英] What does void(U::*)(void) mean?

查看:67
本文介绍了void(U::*)(void) 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 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.*ppu->*p 来访问其内容(其中 uU).

* 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆