2012-04-03 121 views
0

我有一个包含std :: arrays的双端队列。包含数组的结构

我想将它转换为包含结构体的deque。 我所做的结构是这样的:

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

而且我有一个名为访问双端队列:

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; 
    } 
+2

你可以将它形成一个我们可以尝试编译的代码块(即[SSCCE](http://sscce.org))吗?我把上面的代码放到一个文件中,并写了一个main(),它为我编译w/gcc – je4d 2012-04-03 00:11:54

+0

错误来自哪里,哪里是你的示例? – ssube 2012-04-03 00:14:15

+0

@ je4d查看我的编辑 – 2012-04-03 00:24:59

回答

1

的在你的例子PrintBoard声明是它在dfs()使用后。如果这是您的代码结构化的方式,那么您可能会有更早的声明将数组作为参数。您可能在某个地方有一个旧的声明,这个声明正在被您的包含内容拉入。

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

+0

问题是我已经像这样声明了PrintBoard:'void PrintBoard(array ,4> tt)'。正确的是这个'void PrintBoard(New_Array tt)' – 2012-04-03 00:42:01

相关问题