October 9th, 2009, 05:21 PM
Need help with 2d array o.O
hey folks, i need some help with a 2d array that i am using ->
i have a class with the member variables
int m_iScreenWidth, m_iScreenHeight;
int m_iTilesAcross, m_iTilesDown;
then i have in the constructor for the class i have:
Grid::Grid(int iTileWidth, GameEngine*_pGame)
m_pGame = _pGame;
m_iTileWidth = iTileWidth;
m_iScreenWidth = m_pGame->GetWidth();
m_iScreenHeight = m_pGame->GetHeight();
m_iTilesAcross = m_iScreenWidth / m_iTileWidth;
m_iTilesDown = m_iScreenHeight / m_iTileWidth;
m_pBitmapGrid = new Bitmap*[m_iTilesAcross];
Its a very simple class atm, and i plan to expand on it later, but currently i know that the get height and getWidth functions being called work. And all the code above works properly, however the fault comes when i try to make the array into a 2D array:
m_pBitmapGrid = new Bitmap*[m_iTilesAcross][m_iTilesDown];
i get the following compile errors related to the line above:
error C2540: non-constant expression as array bound
error C2440: '=' : cannot convert from 'Bitmap *(*)' to 'Bitmap **'
the two variables that define the size of the array are of the same type and are set to a specific value in the constructor. Even when i made the 2nd dimention of the array [m_iTilesDown] it still didnt compile and gave me the same errors.
But i know that m_iTilesAcross should count as a constant integer becuase it works fine when initializeing just a 1 dimensional array. So why is it that a single dimention array works and a 2d array dosnt. And is there any way around this?
Any help is much appriciated, thank you.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!