gpt4 book ai didi

objective-c - 如何在 Objective-C 中传递 C 风格的矩阵

转载 作者:行者123 更新时间:2023-11-30 15:44:32 25 4
gpt4 key购买 nike

我试图将矩阵传递给我的函数:

int movesMatrix[self.map.width][self.map.height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
movesMatrix[x][y] = -1;
}
}

- (void)foo:(int **)movesMatrix
{
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
NSLog(@"%d,%d - %d", y, x, movesMatrix[x][y]);
}
}
}

但我收到错误:BAD_ACCESS我做错了什么?

最佳答案

尝试更改为以下内容:

- (void)foo:(int *)movesMatrix
...
NSLog(@"%d,%d - %d", y, x, movesMatrix[x*self.map.height + y]);

关于objective-c - 如何在 Objective-C 中传递 C 风格的矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19440206/

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