Qt 项目中的 C++ 语法

标签 c++ qt syntax

我正在尝试编译一个用 C++ 语言的 Qt Project 组件编写的项目,我在其中一个类“DetectAll”中进行了声明,但编译器提示代码语法并恰好在 PointIndex() 处停止。

从该代码中,我了解到 PointIndex 是 Qt 项目固有的变量,并作为函数 DetectAll 中的第二个参数传递。但是编译器也提到了对我来说没有意义的 QPair,你能帮我找出我在这里做错了什么吗?

以下为原代码及编译错误

protected:
.....
bool detectAll(const QPointF& pos, PointIndex& result = PointIndex());

/////////////

D:\....\MAT\Skeleton_source\sswidget.h:87: error: could not convert 'QPair<int, int>()'
 from 'SSWidget::PointIndex {aka QPair<int, int>}' to 'SSWidget::PointIndex& {aka QPair<int, int>&}'
 bool detectAll(const QPointF& pos, PointIndex& result = PointIndex());
                                                                    ^

最佳答案

改变

PointIndex& result = PointIndex()

PointIndex result = PointIndex()

在你的参数声明中。或者删除默认值。您不能将非常量引用绑定(bind)到临时引用。

您正在为引用分配默认值,这是编译器提示的。另外,似乎 SSWidget::PointIndex类型定义为 QPair<int, int>这就是为什么您看到提到的原因。

相关SO问题here .

关于Qt 项目中的 C++ 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19634094/

相关文章:

c++ - QFile:如何有效地只读取从 k 到 k+L 的字节

arrays - 在 Swift 2 中定义不可变字典数组的优雅方式是什么?

scala - 是否可以在 Scala 中声明一个公共(public)字段

c++ - 为什么这个 C++0x 程序会产生意外的输出?

c++ - 如何在 Win32 C++ 中将类型 "int"转换为类型 "LPCSTR"

c++ - 我如何将此信号连接到插槽

c++ - 当我的项目在 Visual Studio 和 Qt Creator 中构建时,Q_ASSERT 具有不同的行为

javascript - 如何在 JavaScript 中将 float 转换为整数?

c++ - GDB 执行错误 : No such file or directory

c++ - 如何禁止在 Windows MFC 应用程序中创建 .pf(预取)文件?