Jump to content
  • Advertisement
Sign in to follow this  
mrtie_dye

Array question

This topic is 4887 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 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
Advertisement
Vectors [and the rest of the STL] are C++. Use the right tool for the job.

And no. It's not doing what you're looking for. iirc bmo should be a **bmo.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
Vectors [and the rest of the STL] are C++. Use the right tool for the job.


Ahh, the beauty of truth[attention]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!