Archived

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

pointer to multi-dimentional array

This topic is 5506 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

Ok, I''ll start with what I''m trying to do. I want to pass a multi-dimentional array to a function. The function definition looks like this: void cConsole::DrawRect(SMALL_RECT &dRect, const CHAR_INFO *dChar) The first parameter gives the width and height of the array, the second gives the address. I want to be able to do this: dChar[10][10] Shouldn''t this work? I also can''t pass it on the other side, like so: CHAR_INFO myChar[10][10]; Console.DrawRect(myRect,myChar); Any thoughts on this?

Share this post


Link to post
Share on other sites
Well, that helped on the function side, but on the passing side I still get this:

error C2664: ''cConsole::DrawRect'' : cannot convert parameter 2 from ''CHAR_INFO [10][10]'' to ''const CHAR_INFO ** ''

Share this post


Link to post
Share on other sites
You can easily calculate the location in a multi-dimensional array by doing the following...

Index = (Y position * Max X size) + X position

That allows you to create a single-dimension array containing multi-dimensional data, like in the case of an int [10][10], for instance. It also makes things simpler, as the compiler doesn''t have to calculate two parameters for addressing your array, when it compiles the code.

Share this post


Link to post
Share on other sites