包含数组的结构
Struct that contains arrays
我有一个包含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
之前移动它的声明。
相关文章:
- C++将文本文件中的数据读取到结构数组中
- JSON转换为nlohmann JSON-lib中的结构数组
- 需要帮助将结构数组传递给函数
- 在 64 位边界上对齐C++结构数组?
- 带有枚举方向/类型的气泡排序结构数组
- 在C++中访问结构数组中的数据
- 从指向结构数组的指针中提取元素
- 如何制作一个地图,其中的值是C++中的结构数组
- 如何在函数中显示结构数组
- 包含作为成员C++函数的结构数组
- 如何修复函数中的 fstream 文件输入以将正确的信息存储在结构数组中?
- std::transform 将一个结构数组复制到另一个结构数组
- 将非托管结构数组封送到托管数组
- 显示结构数组
- 结构数组中所有类似字段的总和
- 结构数组的构造函数错误,错误消息:没有构造函数实例与参数列表匹配
- 在 glsl opengl 中将嵌套结构数组作为统一传递
- 使用初始化列表填充C++中的多维结构数组时出现问题
- 如何将字符串字符与结构数组进行比较?
- C++结构数组