reference array

void iniBoard(signed char&[][2]);
i always getting an error when im declaring a function like this.
whats wrong with this?
Last edited on
Do you want the function parameter to be a reference to the array? In that case you need to specify all array dimensions and put the & in parentheses.

 
iniBoard(signed char(&)[2][2]);


Note that none of the following ways of passing the array will create a copy of the array, so any of them can freely modify the array elements of the original array.

 
iniBoard(signed char(&)[2][2]);

 
iniBoard(signed char[][2]);
Last edited on
i already did that.
void iniBoard(signed char(&)board[][2],const unsigned int*,const unsigned int*,signed char*);
heres my code.
but i get different error
variable or field 'iniBoard' declared void|
i just want the 2d array on my main function to be modified so i can pass it to another func to print it
Last edited on
The variable name should be inside the parentheses and you also need to specify the size of the array.

 
signed char(&board)[2][2]


If you don't want to specify the array size (because it could vary?) you probably don't want to pass it by reference, but instead use:

 
signed char board[][2]

This is the same as

 
signed char* board[2]

Both of the above is exactly the same (in this context) and what is being passed to the function is actually a pointer to the first element in the array.
Last edited on
i see, the var name should be also inside the () and specify the size of array but thats only if i wont change it. yes?
thanks i get it now.

Lorence30 wrote:
i see, the var name should be also inside the () and specify the size of array but thats only if i wont change it. yes?

When you have a reference you have to mention what type the reference is referring to. The size of the array is part of the type so that's why you have to specify the size when working with references.

The second way that I showed you use pointers to the first element in the array so only the type of the array elements need to be specified in that case.
Topic archived. No new replies allowed.