我如何理解这种静态铸造? [英] How do I understand this static casting ?
问题描述
我在理解以下代码行时遇到问题:
I have a problem with understanding the following line of code:
static_cast<void(QButtonGroup::*)(QAbstractButton *, bool)>(&QButtonGroup::m_buttonGroup)
我的尝试:
我搜索了static_cast,并了解它,我知道在这段代码中我们试图转换对象
What I have tried:
I searched for the static_cast, and understand it, i know that in this code we are trying to convert the object
(&QButtonGroup::m_buttonGroup)
到另一种类型:
to another type:
<void(QButtonGroup::*)(QAbstractButton *, bool)>
但我不明白上一行。我们的意思是:
But i do not understand the previous line.what do we mean by:
void(QButtonGroup::*)(QAbstractButton *, bool)
这应该是一个类型,但我无法得到它?
提前谢谢。
this supposed to be a type, but i can not get it?
Thanks in advance.
推荐答案
static_cast<void(QButtonGroup::*)(QAbstractButton *, bool)>(&QButtonGroup::m_buttonGroup)
Star从错误的一端看看括号中的任何内容:
Starting from the wrong end look at whatever is in the parentheses:
&QButtonGroup::m_buttonGroup
m_buttonGroup
是一个静态对象,位于 QButtonGroup
类中。 &
表示使用此对象的地址。这就是要投射的原始项目,以及尖括号中的任何内容(<>
)。尖括号包含:
m_buttonGroup
is a static object, in the QButtonGroup
class. And the &
means use the address of this object. So that is the original item that is to be cast, to whatever is in the angle brackets (< >
). The angle brackets contain:
void(QButtonGroup::*)(QAbstractButton *, bool)
哪个是函数指针定义。 (QButtonGroup :: *)
部分表示这是指向 QButtonGroup
类中某些内容的指针。围绕它的括号告诉我们它是一个函数而不是数据指针。下面的括号包含要传递给函数的参数的定义,前面的 void
部分告诉我们该函数没有返回类型。
如果没有更多背景信息,就不可能多说。
Which is a function pointer definition. The (QButtonGroup::*)
part says this is a pointer to something in the QButtonGroup
class. The parentheses around this tell us it's a function rather than a data pointer. The following parentheses contain the definition of the parameters to be passed to the function, and the preceding void
part tells us that the function does not have a return type.
Without more context it's not possible to say more.
这篇关于我如何理解这种静态铸造?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!