Question regarding two dimensional array
Posted
by Sherwood Hu
on Stack Overflow
See other posts from Stack Overflow
or by Sherwood Hu
Published on 2010-04-19T16:20:55Z
Indexed on
2010/04/19
16:23 UTC
Read the original article
Hit count: 240
c++
|multidimensional-array
I have some problems using two dimensional array in the code and need some help.
static const int PATTERNS[20][4];
static void init_PATTERN()
{
// problem #1
int (&patterns)[20][4] = const_cast<int[20][4]>(PATTERNS);
...
}
extern void UsePattern(int a, const int** patterns, int patterns_size);
// problem #2
UsePattern(10, PATTERNS, sizeof(PATTERNS)/sizeof(PATTERNS[0]));
in the first statement, I need to cast the const off the two dimensional array PATTERNS. The reason for this is that the init function is called only once, and in the remaining code, PATTERNS is strictly read-only.
In the second statement, I need to pass PATTERNS array to the int** argument. Direct passing resulted a compile error.
Thanks!
© Stack Overflow or respective owner