Jump to content
  • Advertisement

Archived

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

Beowulf_

pointer to multi-dimentional array

This topic is 5816 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
Advertisement
Huh?? I''ll give it a try. Thanks for the tip, but could you explain the semantics of that statement? I don''t like to drive blind, if you know what I mean.

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
Hello,

Take a look at http://www.eskimo.com/~scs/C-faq/q6.19.html

I hope this helps.

- lmov

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

  • 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!