int (*iGrid)[4]

Started by
2 comments, last by valles 21 years ago
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
Advertisement
I plugged in the values you gave me, but encountered more errors.

- 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).
Fixed it. Had a float where an int should be somewhere else in the code, runs fine. Thanks for the energy.

This topic is closed to new replies.

Advertisement