Jump to content
  • Advertisement
Sign in to follow this  
Hermes

std

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

Advertisement
Can you elaborate a little more? I am assuming you are talking about building a three-dimensional array in Standard C++. If not please tell me. However, the answer to that would be this:

int threedarray[2][2][2]; //Three dimensional array

Share this post


Link to post
Share on other sites
I need the form from the standard C++(STD) way

This should be a stack of moves initialized at:
32 players
MAX_LEVELS levels
all the moves at every levels pushed accordingly


i made it

vector<vector<vector<unsigned __int64> > >stack;

but i need to initialize the sizes of the first two of them and i don't know how.....[sad]

I also tried :
stack(32,(MAX_LEVEL,std::vector<unsigned __int64>()))
but no luck.....

Share this post


Link to post
Share on other sites
use some typedef magic to help out:


typedef std::vector<unsigned __int64> vec1d;
typedef std::vector< vec1d > vec2d;
typedef std::vector< vec2d > vec3d;

vec3d stack(32, vec2d(MAX_LEVEL));


You might want to look into the method std::vector::reserve if your gonna go down this root [smile] clickly

Or alternatively check-out Boost.MultiArray

Share this post


Link to post
Share on other sites
STL is the actual framework which provides "containers", which are the things you're looking for to produce a "tridimensional array"

"std" is just a namespace, in which the various STL containers are placed - along with all the iostream stuff like 'cin' and 'cout' and 'endl', and a bunch of other things too (including anything you might choose to put in there - but doing so is probably a bad idea).

As for doing the actual initialization: The std::vector constructor that you're probably most interested in here is:
vector(size_type n, const T& t) 	 Sequence 	Creates a vector with n copies of t.


So we're going to make a 1-d array with z many copies of your default element, which represents one item in the 'innermost' dimension of the 'array'. Then we make a 2-d array with y-many copies of that 1-d 'prototype', then a 3-d array with x-many copies of *that*:


vector<int> 1dproto(z, 0);
vector<vector<int> > 2dproto(y, 1dproto);
vector<vector<vector<int> > > arr(x, 2dproto);



You should keep in mind that the resulting structure is more flexible than an ordinary 3-d array in a bunch of ways. It doesn't have to remain rectangular, for example, and it won't use contiguous storage space AFAIK. If you want something that's still constrained to be rectangular (and keeps everything together in a single allocation) but still lets you resize each dimension, you'll probably have to write some wrapper code on top of a single vector.

Or you could just look into boost::multi_array. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by snk_kid
use some typedef magic to help out:


typedef std::vector<unsigned __int64> vec1d;
typedef std::vector< vec1d > vec2d;
typedef std::vector< vec2d > vec3d;

vec3d stack(32, vec2d(MAX_LEVEL));


You might want to look into the method std::vector::reserve if your gonna go down this root [smile] clickly

Or alternatively check-out Boost.MultiArray


I had a friend who has that Library, but I'm confused on how to install it with DevCpp

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!