Jump to content
  • Advertisement

Archived

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

help, cant get array to work

This topic is 5582 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 cannot seem to get this to work, any ideas? //in my main header i have this... // //i will use the struct array in several diffrent files// struct CityStruct { HBITMAP City; }; CityStruct CityArray[10][10]; //in another file i have this// void GenerateMap(struct CityArray[10][10]) { for(int y = 0; y < 10; y++) { for(int x = 0; x < 10; x++) { CityArray[x][y].City = LoadABitmap("grass.bmp"); //parse error before '[' i tried (struct CityStruct CityArray[10][10].. didnt work either... } } } [edited by - when4 on February 7, 2003 4:10:18 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Well your problem is 2 fold.

1) First you named a global variable CityArray and then used this same variable name for the array passed into your function. This won''t work because it won''t beable to tell what''s what.

2) Secondly you can''t pass in a 2d array to a function like you were trying to do. It''s a better idea to pass a pointer to the array. Or in your case because it''s a 2d array you pass a double pointer.


The following code should solve your compile problems.


  
struct CityStruct
{
HBITMAP City;
};

CityStruct CityArray[10][10];

void GenerateMap(CityStruct **pCityArray)
{
for(int y = 0; y < 10; y++)
{
for(int x = 0; x < 10; x++)
{
pCityArray[x][y].City = LoadABitmap("grass.bmp");
}
}
}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!