Archived

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

kmsixpence

a variably clarification question

Recommended Posts

Okay, i think i understand it but i wanted to clear this up. I need a way to declare globals on the spot. If i declare a variably in my game_init() function, my game_loop() fuction cannot access it so I think i know how to solve it. So would i have to do something like the following?
  
int newints* = new int[10];
newintvar = 1;


//in the game_done() function

delete newints
  
could some1 please tell me if this is correct

Share this post


Link to post
Share on other sites
No, thats not what i meant. I meant something like creating a variable in a function that does not terminate when the function returns. I wanted it to be created in the game_init() function and deleted in the game_done() function.

Share this post


Link to post
Share on other sites
Is that what you want ?

    
int* newints; // at the top of the source file


.
.
.

void
game_init()
{
newints = new int[10];
}


void
game_loop()
{
newints[0] = 5;
newints[1] = 10;
}

void
game_done()
{
delete[] newints;
}



Edited by - Fruny on November 18, 2001 5:55:45 PM

Share this post


Link to post
Share on other sites
How about something like this?
  
int* newInts;

void Game_Init(void)
{
newInts = new int[10];
...
}
...
void Game_Done(void)
{
delete[] newInts;
...
}

Share this post


Link to post
Share on other sites