Sign in to follow this  
mrtie_dye

Array question

Recommended Posts

I need to be able to create a 2 dimensional array of objects which has both dimension sizes specified dynamicaly. As we know, c++ does not like you to do that. So, I have tried to figure out a work around. The code below compiles fine, but is it doing what I think it is? Any comments, suggestions, better ways to do this, please let me know. I know vectors would most likely make this easier, but I am just expirementing with c++. I will get into the STL later. Thanks
/*This class will eventually allow me to load a bitmap file and
break it up into tiles. It uses a class called BitMapObject to load
these files into something the Win32 api can understand. Just know that
BitMapObject is an object defined elsewhere.*/

CBmpTiler::CBmpTiler(HWND hwndMain, WORD img, int rows, int cols)
{
	hwnd = hwndMain;

        /*This is the name of the resource, as specified in resource.rc.
        For example, this might be something like IDC_PICOFSOMETHING*/
	imgName = img;

        //The number of rows and collums the image is to be split up into
	numRows = rows;
	numCols = cols;
	
        /*bmo is declared elsewhere as a pointer to type BitMapObject
        For Example: BitMapObject *bmo;*/
	bmo = new BitMapObject[numRows];

        //Loop through each element in bmo...
	for(int a = 0; a < numRows; a++)
	{
                //then we make a new array....
		BitMapObject *bmo1 = new BitMapObject[numCols];

                //then point this element at the new array
		bmo[a] = *bmo1;
	}
}

CBmpTiler::~CBmpTiler()
{
	if(bmo)
	{
                //Loop through each element in bmo...
		for(int a = 0; a < numRows; a++)
		{
                        //then I think this destorys the pointer in each element
			delete bmo[a];
		}
                //this should finish bmo off
		delete bmo;
	}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this