本文介绍了“:"是什么意思?(单个冒号)在“Klass:method(p)"中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我看到了这段代码:

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??
}

并且只警告未使用的标签QTreeWidget",编译成功.: 是什么意思?

And only warned "unused label QTreeWidget", compiled successfully. What does : mean?

推荐答案

预期的代码可能是 QTreeWidget::dragMoveEvent(event); 如您所想.如果 CameraTree 继承自 QTreeWidgetQTreeWidget::dragMoveEvent(event) 不需要是静态的才能从 CameraTree 调用>.在 C++ 中,标签用单个冒号 : 表示.QTreeWidget:dragMoveEvent(event); 编译的原因是因为 QTreeWidget: 被解释为一个标签,然后 dragMoveEvent(event); 是一个递归打电话.

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.

这篇关于“:"是什么意思?(单个冒号)在“Klass:method(p)"中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 02:00