Passing a 2D array of Structs by referencePassing a 2D array of Structs by reference

SO im pretty new to c++ and im trying to pass a 2D array of a struct type by reference to a function. As far as i know they are automatically passed by reference. Here is my code.The problem is probably obvious but i cant figure it out. The complier keeps saying variable or field "function" declared void and bArray was not declared in this scope and it expected ")" before bArray.I think that the compiler is not recognizing that i want to pass an array which is creating the "function declared void" error and is also why it wants a ")" before bArray. So im guessing that my format for my prototype is not correct. Does anyone know what is wrong with it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void function(balloons bArray[][5]);

int main()
{
    struct balloons
    {
           float totalWeight;
        float largestBalloon;
    };
      balloons balloonsArray[20][5];

    function(balloonsArray);
    return 0;
} 

void function(balloons bArray[][5])
{
    bArray[1][1].totalWeight = 1.0;
    bArray[1][1].largestBalloon = 1.0;
}
Then the compiler meets the declaration

void function(balloons bArray[][5]);

it does not know what is ballons. So it will issue an error.

You should place the declaration of balloons before the function declaration.
As for the array then it is passed by value as you specified and is implicitly converted to the pointer to the first element of the array.
ok i fixed that and now im getting
proj1.cpp:85: error: variable or field ‘function’ declared void
proj1.cpp:85: error: expected ‘)’ before ‘bArray’

this is at the function declaration, any ideas?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
struct balloons {
        float totalWeight;
        float largestBalloon;
    };
      balloons balloonsArray[20][5];

void function(balloons bArray[][5]);

int main() {
    function(balloonsArray);
    return 0;
} 



{
void function(balloons bArray[][5])
{
    bArray[1][1].totalWeight = 1.0;
    bArray[1][1].largestBalloon = 1.0;
}


Remove the first brace

{
void function(balloons bArray[][5])
{
Topic archived. No new replies allowed.