我有
struct board{
int x[3];
int y[3];
};
// in the class PatternReader
board PatternReader::testPattern1DX() {
struct board aBoard;
int x[3] = { 1,1,1 };
aBoard = x;
return aBoard;
}
错误是“int *
赋值中的不兼容类型”。
如何设置结构内的数组?
最佳答案
您不能分配数组。但是,您可以初始化结构:
board PatternReader::testPattern1DX()
{
board aBoard = {
{1, 1, 1},
{2, 2, 2}
};
return aBoard;
}
这会初始化 y
以及 x
。
关于c++ - 如何在 C++ 中的结构中设置一个 int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21586598/