[英]Qt QVector of multidimensional array
我正在尝试创建多维数组(C ++数组类)的QVector,但是我遇到了麻烦
我有一个“节点”类,我想将多维数组的QVector作为节点类构造的参数进行传递,但这不起作用,我遇到了编译错误!
Class node {
node(QVector<array<array<int, SIZE>, SIZE>> v);
}
任何人都有我应该如何进行的想法?
节点(QVector,SIZE >> v);
没有C ++ 11及更高版本,该文件将无法编译。 您需要两种解决方法:
node(QVector<array<array<int, SIZE>, SIZE> > v);
// ^space
node(QVector<array<array<int, SIZE>, SIZE> > v);
正确, 无变化; 它起作用 。 将其放入您的qmake项目文件中:
CONFIG += c++11
但是,由于您似乎使用“ C ++数组”,因此需要后一种解决方案。 换句话说,只需添加c ++ 11编译支持即可。
您还有其他问题:
我不确定您从哪里获得Class
资本的念头。 应该是书面class
。
另外,您固有地需要在类之后使用分隔符( ;
)。
您最好不要在头文件中使用array
,而应在std::array
。
这是我的工作示例:
#include <QVector>
#include <array>
const int SIZE = 5;
class node {
node(QVector<std::array<std::array<int, SIZE>, SIZE>> v) {}
};
int main()
{
return 0;
}
TEMPLATE = app
TARGET = main
CONFIG += c++11
SOURCES += main.cpp
qmake && make && ./main
尝试在>>
之间添加空格。 例如:
class node {
node(QVector<array<array<int, SIZE>, SIZE> > v);//space here!
};//don't forget
您需要此空间,因为编译器认为您要使用>>
运算符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.