int (*iGrid)[4]
I created this bit of experimental code:
int (*iGrid)[4];
I access it later as:
iGrid = new int[4][4];
iGrid[3][3] = 5;
Then I try to access it later as:
int bobby = iGrid[3][3];
The error is:
error C2440: ''='' : cannot convert from ''int (*)[4]'' to ''int''
HELP!?!
- Valles Marineris
quote:
also, try declaring iGrid as: int **iGrid;
then allocate the memory: iGrid = new int [4][4];
This absolutely won''t work. Please don''t reply if you don''t know what you''re talking about.
Declaration of iGrid: iGrid is a pointer to an array size 4 of int.
The creation using "new" in the original post is fine. The assignment in the first section is fine. The assignment in the second section is ALSO fine. The error seems to indicate that the compiler didn''t see the [3][3] part, as the type of just "iGrid" is int(*)[4].
In fact, this program works just fine:
int main() { int (*iGrid)[4]; iGrid = new int[4][4]; iGrid[3][3] = 0; int bobby = iGrid[3][3]; return bobby;}
Thus, I''d look for typos, or weird #defines, or something like that; the original understanding of pointers and arrays was sound (as opposed to the reply).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement