[英]Setting an array as a modifiiable parameter of a function in C++
I'm trying to set an array as an input parameter to a self-made function, in which I want to modify the values of the array.我试图将一个数组设置为一个自制函数的输入参数,我想在其中修改数组的值。 For that, I tried to set the input array in the definition of the function as a pointer, but gave me some trouble.
为此,我尝试将函数定义中的输入数组设置为指针,但给我带来了一些麻烦。
The part of the *.hpp file can be seen here: *.hpp 文件的部分可以在这里看到:
void CrossWall(int, int, bool[]);
The part of the *.cpp file is the next one: *.cpp 文件的部分是下一个:
void NODE::CrossWall(int robot_x, int robot_y, bool done_checking[]){
if (((robot_x+1) > (current_map.CheckLength() - 1)) && !done_checking[3] ){
available_movements[3] = 0;
done_checking[3] = true;
}
if (((robot_x-1) < 0 ) && !done_checking[2]){
available_movements[2] = 0;
done_checking[2] = true;
}
if (((robot_y+1) > (current_map.CheckHeight() - 1)) && !done_checking[0]){
available_movements[0] = 0;
done_checking[0] = true;
}
if (((robot_y-1) < 0 ) && !done_checking[1]){
available_movements[1] = 0;
done_checking[1] = true;
}
}
The array I want to modify is the array of bools (the only one there).我要修改的数组是 bool 数组(那里唯一的一个)。
I think I found a point of confusion:我想我发现了一个困惑点:
won't do it because it isn't a pointer.
不会这样做,因为它不是指针。
In fact, it IS a pointer: What is array to pointer decay?事实上,它是一个指针: 什么是数组到指针衰减?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.