c++qtmultidimensional-arrayqvector

Qt QVector of multidimensional array


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?


Solution

  • 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:

    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