help, cant get array to work
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]
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.
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"); } }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement