【问题标题】:Qt C++ - QList<float**> type not allowedQt C++ - QList<float**> 类型不允许
【发布时间】:2012-11-27 18:48:07
【问题描述】:

我想将 float** 参数列表传递给仅适用于 C-syle 和 float** 的某个方法(但我们认为我们可以将 QList&lt;&gt; 作为参数类型)。

我试过了

QList< float** > list_ = new QList< float** >();

但这不起作用。我应该改用什么? Qt 容器将用于 2D 矩阵列表吗?

谢谢

【问题讨论】:

  • 为什么这“不起作用”?你有错误吗?哪一个?
  • 那是因为您使用了new 运算符,它将在堆上分配它并返回一个指针。在等号之后你不需要做任何事情。

标签: c++ arrays qt list types


【解决方案1】:

您正在使用类似 java 的语法(或 c# 或其他)

在 C++ 中应该是

QList<float**> *list_ = new QList<float**>() ;   //Pointer to a heap allocated list, Closer to what you wanted to do i think. NEED TO CALL "delete list_" once you are done with it.

QList<float**> list_; //List on the stack, more c++ish, destroyed once it goes out of scope.

【讨论】:

  • 由于隐式共享,在堆上创建 Qt 容器几乎总是荒谬的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-16
  • 1970-01-01
  • 2016-05-08
  • 2010-09-16
相关资源
最近更新 更多