Skip to main content
gamedev.net
🔒 Locked

help with pointers

Started by r3n3gad3 Jul 17, 2003 at 7:57 AM 1 replies 250+ views
Original Post
r3n3gad3
r3n3gad3
hi... i am trying to make a tile sliding game and i wanted to create an array of pointers to point to an array of objects... the point of this was to say the random number random thingo put the number 7 in array[2] then pntrarray[7] would point to this array and when the user says to slide that pntrarray then all i would have to do is pntrarray[x] = last;... which is really easy... i tried to do this in the following code int array[9]; int *pntrarray = new int [9]; for (int i=0; i < 9; i++) { now: num = rand() % 9; if (!chknum()) { //this function checks to see if there is //no array with the same number array = num pntrarray[num] = & array[i] }else{ goto now; } }
Yanroy
Yanroy
*dies of a heart attack* That goto.... eeek. I think you could replace it with continue. Anyways, You didn''t really ask a question here, but I think I might see your problem anyways. Unless I''m mistaken, you want an array of pointers, not a pointer to an array (yes, there is a difference!). When you have
int *pntrarray = new int [9]; 
you are creating a pointer to an array of 9 ints. Try replacing it with
int *pntrarray[9]; 
And in the future, post more code and a more complete description/question, please

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
Chacha
Chacha
Goto statements are very bad practise, try to avoid them at all costs (there will always be a way around them, and like Yanroy has suggested, you could have used continue in your loop example).

Also, when posting some source code, enclose it in the source tags to make it more readable.

cya later

[edited by - chacha8 on July 19, 2003 8:00:29 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.