invalid array access on passed by reference array

 

Hey Guys,

im struggeling on a realy simple problem but can't find a solution. I have this simple code:

void test(OrderObject& array[]) {
   for (int i = 0; i < array.size(); i++) {
      // do something here
   }
}

This gives me the errors:

'array' - invalid array access

'size' - function not defined

Can anyone tell me what im doing wrong here?

 
Change array.size() to ArraySize(array)
 
Fabio Cavalloni #:
Change array.size() to ArraySize(array)
Oh wow i knew it must be this simple :D Thank you!! Works without error now.
 
It looks like you're trying to define a function `test` that takes an array of `OrderObject` objects as a parameter. However, the syntax you've used for passing the array reference `OrderObject& array[]` is not valid in C++. Instead, you can pass an array pointer or a reference to an array. Here's an example using a reference to an array:

```cpp
void test(OrderObject (&array)[], int size) {
   for (int i = 0; i < size; i++) {
      // do something here with array[i]
   }
}
```

In this example, `OrderObject (&array)[]` declares a reference to an array of `OrderObject` objects, and `int size` is used to specify the size of the array. You would call this function like `test(myArray, arraySize)`, where `myArray` is your array of `OrderObject` objects and `arraySize` is the size of the array.

Alternatively, if you want to pass an array pointer, you can do it like this:

```cpp
void test(OrderObject* array, int size) {
   for (int i = 0; i < size; i++) {
      // do something here with array[i]
   }
}
```

And call it as `test(myArray, arraySize)`, where `myArray` is a pointer to your array of `OrderObject` objects and `arraySize` is the size of the array.