What does “:” (a single colon) mean in “Klass:method(p)”?

*爱你&永不变心* 提交于 2021-02-16 20:54:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!