Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


int (*iGrid)[4]

This topic is 5716 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
Guest Anonymous Poster

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).

Share this post

Link to post
Share on other sites
Fixed it. Had a float where an int should be somewhere else in the code, runs fine. Thanks for the energy.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!