问题
Today I saw this code:
void CameraTree::dragMoveEvent(QDragMoveEvent *event)
{
QTreeWidget:dragMoveEvent(event);
}
I think the above code is wrong. But:
void CameraTree::dragMoveEvent(QDragMoveEvent *event)
{
dragMoveEvent(event);//infinite recursion???
}
void CameraTree::dragMoveEvent(QDragMoveEvent *event)
{
QTreeWidget::dragMoveEvent(event);
// I understand is called dragMoveEvent in class QTreeWidget.
// But dragMoveEvent is not static??
}
And only warned "unused label QTreeWidget", compiled successfully. What does :
mean?
回答1:
The intended code was probably QTreeWidget::dragMoveEvent(event);
as you thought. QTreeWidget::dragMoveEvent(event)
does not need to be static to be invoked from CameraTree
if CameraTree
inherits from QTreeWidget
.
In C++, labels are indicated with a single colon :
. The reason QTreeWidget:dragMoveEvent(event);
compiles is because QTreeWidget:
is interpreted as a label and then dragMoveEvent(event);
is a recursive call.
来源:https://stackoverflow.com/questions/47149006/what-does-a-single-colon-mean-in-klassmethodp