Jump to content
  • Advertisement

Archived

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

uber_n00b

Quick question about pointers

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

if I declare a pointer like this:
int *i[3]
Am I making an array of pointers or a pointer to an array? If not, how do I make an array of pointers?

Share this post


Link to post
Share on other sites
Advertisement
"int *i[3]" declares an array of pointers.
I too sometimes get confused with this kind of stuff,and i''ve seen that typedef makes my programs more readable.

Example:
typedef int *Pint;
Pint i[3];

Share this post


Link to post
Share on other sites
OK well I have another problem then. How do I make an array of pointers that in turn points to an array?

I tried to do


bool *booleans = new boolean[5][3];


But yeah didn't work. How should I do it? I mean am I making myself clear enough? Should I make a vector of boolean*?

[edited by - uber_n00b on June 1, 2004 3:40:40 PM]

Share this post


Link to post
Share on other sites
The array name points to the first element of the array, with a little abuse, we could say that arrays are pointers.

Maybe if you explained what you are trying to implement ?

Share this post


Link to post
Share on other sites
Alright here''s the setup: I have an octree and each node contains three different sets of details: low detail, medium detail and high detail. Each level of detail stores the polygons in this way:

POLYGON *POLYS = new POLYGON[NUM_POLYS].

How do I create an array such that low, medium and high detail can be stored in one array that each element holds the pointer to the array which holds the polygons? Does that make sense?

Share this post


Link to post
Share on other sites
an array of pointers to arrays:


int** pTemp;

pTemp = new int*[50];

for(int i = 0; i < 50; i++)
{
pTemp[i] = new int[50];
}

Share this post


Link to post
Share on other sites
I'm not 100% this is the only way to do this,but here goes:

say for a 10x5 array:

bool (*booleans)[10]=new bool[5][10];
so you see that the number of columns must be known in compile-time

If you want to be able to define both rows and columns in run-time,do this:

bool **i;
i=new bool*[ROWS];//Create an array of arrays
for (int j=0;j{
i[j]=new bool[COLUMNS];//Create an array of bools
}


-EDIT:Oops,I see Etnu was faster than me.Oh well,we boid said the exact same thing.



[edited by - mikeman on June 1, 2004 4:14:23 PM]

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!