Jump to content
  • Advertisement


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


dynamic 2d array

This topic is 5797 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 am trying to figure out how to declare a dynamic 2d array and use it. My book says to use: note: in my class MagicSquare, I have double **pMagicSquare as the declaration

void MagicSquare::Generate(void)
	int Row_Index = 0, Col_Index = Col_Size / 2, current_count = 1;
	pMagicSquare = new double* [Col_Size];
	for(int i = 0; i < Col_Size; i++)
	       pMagicSquare[i] = new double[Row_Size];
	memset(pMagicSquare, 0, sizeof(pMagicSquare));

	pMagicSquare[Row_Index][Col_Index] = current_count++;
I get an error saying I can't access pMagicSquare[0][1] when I make it a 3x3 2d array. I don't understand what I've done wrong here, and have been messing with it for three days now. [edited by - xg0blin on September 1, 2002 2:51:22 PM]

Share this post

Link to post
Share on other sites
First of all I''d like to ask you to specify the compiler error you get, it will be easier to debug.

Second of all, the only lead I have by glancing at it quickly is the
Col_Index = Col_Size / 2
pMagicSquare[Row_Index][Col_Index] = current_count++;

Now, I have no idea how you built your program, but Col_Index could generate unsuspected compiler errors if its value turns out to be a floating-type.
I mean, this doesn''t work: array[1][2.35] = x;

I don''t know... really I don''t. I''m just too tired, heh.

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.

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!