Jump to content
  • Advertisement
Sign in to follow this  
lomateron

passing a 3D array with different size to a function

This topic is 1411 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 have:

 

char cubesA[100][100][100];
char cubesB[30][30][30];

how can I pass them as a parameter to access them using the three square brackets[][][] inside a fuction?

 
this:
 
void function( char cubes[][a][b] )
{
     //---
}
 
doesn't works here because the "a" and "b" can be 30 or 100
 
is there no way?
Edited by lomateron

Share this post


Link to post
Share on other sites
Advertisement

Hi.

Try function(char ***ar, DWORD size1, DWORD size2, DWORD size3)

Edited by ankhd

Share this post


Link to post
Share on other sites
You also might consider make a cube struct and then define one or more std::vector's with them. So you can simply pass a pointer to the vector or the vector itself if you like

Share this post


Link to post
Share on other sites

Hi.
Try function(char ***ar, DWORD size1, DWORD size2, DWORD size3)


Nope nope. This is C++.

That says a pointer to a pointer to a pointer to an object.

In C and C++ multidimensional arrays are laid out continuously and accessed based on stride. The compiler is smart enough to use those sizes and do the stride for you.

In this case, you would need the parameters for sizes, but just pass a pointer. Then add the stride. That is ((y*xstride)+x) or ((z*xstride*ystride)+(y*xstride)+x) or more depending on your dimensionality.

Share this post


Link to post
Share on other sites

What are you trying to do?

 

Often times when your program calls for a multidimensional array it's better to put that array in an object that better restricts legal operations on the array. So instead of passing around an array, you would pass around an object that internally used an array in it's implementation.

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!