Qt QVector of multidimensional array

802 Views Asked by At

I'm trying to create a QVector of multidimensional array(C++ array class) but I'm facing troubles with it

I have a class "node" and I want to pass the QVector of a multidimensional array as a parameter of the node class construct but this isn't working, I'm a getting a compile error!

Class node {
    node(QVector<array<array<int, SIZE>, SIZE>> v);
}

any one has an idea of how should I proceed?

2

There are 2 best solutions below

0
On BEST ANSWER

node(QVector, SIZE>> v);

That will not compile without C++11 and on. You need two ways to address it:

Pre-C++11

node(QVector<array<array<int, SIZE>, SIZE> > v);
//                                        ^space

C++11 and post

node(QVector<array<array<int, SIZE>, SIZE> > v);

Correct, no change; it just works. Put this into your qmake project file:

CONFIG += c++11

However, since you seem to use "C++ array", you will need the latter solution. In other words, just add c++11 compilation support to you build.

You have further issues, too:

  • I am not sure where you got the idea of capital for the Class. It should be written class.

  • Also, you inherently need the separator (;) after a class.

  • You better do not use array in header files, but std::array.

This is my working example:

main.cpp

#include <QVector>
#include <array>

const int SIZE = 5;

class node {
    node(QVector<std::array<std::array<int, SIZE>, SIZE>> v) {}
};

int main()
{
    return 0;
}

main.pro

TEMPLATE = app
TARGET = main
CONFIG += c++11
SOURCES += main.cpp

Build and Run

qmake && make && ./main
7
On

Try to add space between >>. For example:

class node {
    node(QVector<array<array<int, SIZE>, SIZE> > v);//space here!
};//don't forget

You need this space because compiler think that you want to use >> operator.