Jump to content
  • Advertisement

Archived

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

edwinnie

returning a 2D array of pointers...

This topic is 5529 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 understand how to return a 1d array of pointers from a function. but how to do it in 2d? eg return type for 1d array of ptrs: Crystal** return type for 2d? Crystal*** heelps!! Edwin

Share this post


Link to post
Share on other sites
Advertisement
unfortunately that doesnt seem to work

i got this error stating unable to convert from
Crystal*[10][20] to Crystal***

heelps!

Edwin

Share this post


Link to post
Share on other sites
Here''s the deal with 1D versus 2D arrays.

A 2D array isn''t really a 2D array. After all, there''s no such thing as 2D memory; it''s all organized in a line. (Okay, just shut up, all the EE majors in the house.) So what your compiler does, when it sees something like this:

int a[5][6];

is it ACTUALLY allocates a line of 30 integers. Since it knows that each row has five values, when you access array element, say, [2][3], it multiplies 2 by 5 and adds 3.

But when you''re just returning an array like that, there''s no way for the compiler to know how long a row''s going to be. That''s why you can''t convert.

What most people do in this situation is make a 1D array, and manually do the element calculations that the compiler normally does for you. This is the most painless.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Good reply on the not really 2D arrays.

You can take that a whole step further even, and say that arrays aern''t really arrays

int booger[5][6];

for example the above is a multidemensional array right?

however the identifier booger is also a pointer This is dangerous; but also a really handy tool sometimes

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!