包含数组的结构

Struct that contains arrays

本文关键字:结构 数组 包含      更新时间:2023-10-16

我有一个包含std::数组的deque。

我想把它转换成包含结构的deque。我做的结构是这样的:

struct New_Array {
array<array<int,4>,4> tablee;
int h;
} Jim;

我有一个名为visited的deque:

deque<New_Array> visited;

我有一个类似的函数,可以打印名为PrintBoard的数组。

    void PrintBoard(New_Array tt) {
        using namespace std;
        for (int iRow = 0; iRow < 4; ++iRow) {
            for (int iCol = 0; iCol < 4; ++iCol) {
                cout << tt.tablee[iRow][iCol];
                cout << "  ";//This space helps so the numbers can be visable 
            //to the user 
}
            cout << endl;
        }
}

当我写PrintBoard(visited.front());时,它会给我error C2664: 'PrintBoard cannot convert parameter 1 from 'New_Array' to std:tr1::array<_Ty,Size>'.

问题出在哪里?我从来没有把表格作为一个维度。

编辑:

 #include <deque>
    #include <vector>
    #include <array>
    using namespace std;
    struct New_Array {
        array<array<int,4>,4> tablee;
        int h;
    }str_test,Jim;
    deque<New_Array> visited;
    void dfs()
    {
    PrintBoard(visited.front());//****the error is in this line****
    }
    void PrintBoard(New_Array tt) {
            using namespace std;
            for (int iRow = 0; iRow < 4; ++iRow) {
                for (int iCol = 0; iCol < 4; ++iCol) {
                    cout << tt.tablee[iRow][iCol];
                    cout << "  ";//This space helps so the numbers can be visable 
                //to the user 
            }
                cout << endl;
            }
            }
    int main() 
    {
        dfs();
        char test_char;
        cin>> test_char;
        return EXIT_SUCCESS;
    }

示例中PrintBoard的声明在dfs()中使用的位置之后。如果这是代码的结构方式,那么您可能会在前面有另一个PrintBoard声明,它将数组作为参数。很可能你在某个地方有一个旧的声明,正被你的include拉进来。

请尝试在使用PrintBoard之前移动它的声明。