Can anyone tell what's wrong here? I can't get the value sent to the function
code:
board::board()
{
char pine[4][4] = { 'O' }; //assign O to all elements
pine[0][4] = 'P'; //single element initialization
...}
Thanks.
Printable View
Can anyone tell what's wrong here? I can't get the value sent to the function
code:
board::board()
{
char pine[4][4] = { 'O' }; //assign O to all elements
pine[0][4] = 'P'; //single element initialization
...}
Thanks.
watch out!
char pine[4][4];
pine[0][4] <- bad mistake
an array goes from 0 to n-1
sorry, that 's a typo. Except for that, anything I should know about pass the array? I tried with one dimensional array and it worked. I don't know when it comes to 2d, things screwed up.
mhm, yeah ok!
2dim arrays are very unconfortable
you should use std::vector<std::vector<char> >
but the problem with 2dim arrays is that you can't pass them as a 2dim array
void foo(char x[5][5]);
char x[5][5];
foo(x);
that works - but you have to specify the size of the array and that makes your program too static!
so you have to use a pointer:
void foo(char*);
char x[5][5];
foo(&x[0][0]);
but if you want to change x[2][3] in foo you have to write:
arr[(2*y)+3]=bla;
y has to be the y-dimension of your array (in our version 5)
that is ugly and unsave - so you better use vector ;-) declared in <vector>