gpt4 book ai didi

c - 结构数组的参数类型不兼容

转载 作者:太空宇宙 更新时间:2023-11-04 02:27:01 24 4
gpt4 key购买 nike

我有一个结构定义为

struct Bod{
int x, y;
};

然后我有一个函数

void add(struct Bod* s) {
h[++nh] = s;
}

在下一个函数中,我试图将数组传递给上一个函数,这给了我错误Incompatible type for argument 1 of function add()

void bfs(struct Bod* body, int start_index){

struct Bod* v;
add(body[start_index]);
...
}

在 main 中,我创建了这样的结构数组

struct Bod body[m*n];

我错过了什么?

最佳答案

由于 body[start_index] 在索引 start_index 处为您提供 一个 body 元素,您最终通过在该单个元素中添加 add()

如果想传入数组本身,只需要原样传入body即可:

add(body);

或者,传入从给定索引开始的数组:

add(&body[start_index]);

关于c - 结构数组的参数类型不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49614456/

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