简体   繁体   中英

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:

void CrossWall(int, int, bool[]);

The part of the *.cpp file is the next one:

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).

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM