gpt4 book ai didi

c++ - 错误 : incompatible types in assignment of `int' to `int[2]'

转载 作者:搜寻专家 更新时间:2023-10-31 00:18:58 24 4
gpt4 key购买 nike

以下 C++ 代码:

int iBlocks[9][2];
class System{
void setBlocks(){
int iUCtr = 0;
int iUYCtr = 105;
while(1){
int iUXCtr = 180;
while(1){
iBlocks[iUCtr] = 0; //error happens here.
iBlocks[iUCtr][0] = iUXCtr;
iBlocks[iUCtr][1] = iUYCtr;
iUCtr += 1;
iUXCtr += 120;
if(iUXCtr>420) break;
}
iUYCtr += 120;
if(iUYCtr>345) break;
}
}
public:
System(){
setBlocks();
cout << "Block settings set..." << endl;
}
};

MinGW g++ 产生此错误:

incompatible types in assignment of `int' to `int[2]'

问题出在 iBlocks[iUCtr] = 0;

当我将 iBlocks 更改为指针时,它起作用了。有人可以向我解释幕后发生的事情吗?

最佳答案

您正在尝试将矩阵的整“行”设置为“0”值。编译器不会让你这样做。

也许你错过了第二个索引,因为 iBlocks 是一个矩阵,你需要的是这样的:

iBlocks[iUCtr][SecondIndex] = 0 

如果您尝试用 Zeros 初始化整个矩阵,请编写一个函数来执行此操作。

关于c++ - 错误 : incompatible types in assignment of `int' to `int[2]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9228528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com