Search code examples
c++arraysdebuggingstructdeque

Struct that contains arrays


I have a deque that contains std::arrays .

I want to convert it to deque that contains structs. The struct I made is like this :

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

And I have a deque that is named visited:

deque<New_Array> visited;

I have a function like that prints the array named 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;
        }

}

When I write PrintBoard(visited.front()); it gives me error C2664: 'PrintBoard cannot convert parameter 1 from 'New_Array' to std:tr1::array<_Ty,Size>'.

What is the problem? I never used tables as one-dimension.

EDIT:

 #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;
    }

Solution

  • The declaration of PrintBoard in your example is after where it is used in dfs(). If this is the way your code is structured, then you may have another PrintBoard declaration earlier that takes an array as an argument. It is likely that you have an old declaration in there somewhere that is being pulled in by your includes.

    Try moving the declaration of PrintBoard before its use.