Skip to main content
GameDev.net gamedev.net
🔒 Locked

really really simple C++ question

Started by mattd Jul 10, 2000 at 8:19 PM 9 replies 550+ views
Original Post
mattd
mattd
(ohmygod - it's related to programming!) uh............. how do we use 'new' to make a multidimensional array? i thought it was something like this..
        

class stuff
{
  public:
    stuff(int x, int y)
    {
      grid = new short int[3][x][y];
    }
  protected:
    short int* grid;
};

int main(void)
{
  stuff foo(3, 5);
  return 0;
}

    
hope i got those source tags right... plz help mattd
The world is your message board - (edited to be politically correct) Edited by - mattd on 7/10/00 8:22:01 PM
mattd
mattd
someone better reply soon or i''m going to .........

.......
.............
.........................
........do something bad



The world is your message board - (edited to be politically correct)
Pouya
Pouya
        
class stuff
{
public:
stuff(int x, int y)
{
grid = new (short int **)[3];
for (int i=0; i<3; i++)
{
grid[ i ] = new (short int *)[x];
for (int j=0; j<x; j++)
grid<i>[j] = new (short int)[y];
}
}
protected:
short int ***grid;

// umm, dont forget to free everything!

};

int main(void)
{
stuff foo(3, 5);
return 0;
}


----------------
- Pouya / FOO!!!
***CENSORED***


Edited by - pouya on July 11, 2000 1:55:23 AM
The Alchemist
The Alchemist
well who teach this to me was my old C teacher and he was a idiot so it maybe be wrong, you can´t declare arrays with variables on it, i don´t know why i´m only a newbie too.

============
-and i will make a termal usine with concrete, plutonioum and paper bags.
-nanny we have paper bags???
gonzo. Muppet babies
"Everything works out in the end, if it doesn't then it is not the end"
The Alchemist
The Alchemist
you have quick fingers pouya.

============
-and i will make a termal usine with concrete, plutonioum and paper bags.
-nanny we have paper bags???
gonzo. Muppet babies
"Everything works out in the end, if it doesn't then it is not the end"
Pouya
Pouya
quote:
Original post by The Alchemist

you have quick fingers pouya.





that happened after 6 years of only seeing a monitor right in front of me (notice that i''ve gone a bit insane?)

----------------
- Pouya / FOO!!!
***CENSORED***
mattd
mattd
thnks pouya



The world is your message board - (edited to be politically correct)
Pouya
Pouya
quote:
Original post by mattd
The world is your message board - (edited to be politically correct)


see, now all the ppl are gonna think that some plotical things are going on in here (my sig first, then yours, who''s next?)

----------------
- Pouya / FOO!!!
***CENSORED***
mattd
mattd
ok - here''s another one - when deleting this mutlidimensional array, do i have to do

    
~stuff(void) {
for(int temp=0;temp<3;temp++)
for(int temp2=0;temp2<mapX;temp2++)
for(int temp3=0;temp3<mapY;temp3++)
delete[temp][temp2][temp3] grid; // is this right?

}
[/source]

or just

[source]
~stuff(void) {
delete[] grid;
}


?

help pouya - you''re pretty fast



The world is your message board - (edited to be politically correct)
mattd
mattd
oops... silly [source] bug.....

anyways i''m sure you''re all smart enought to figure it out



The world is your message board - (edited to be politically correct)
Pouya
Pouya
    
stuff::~stuff(void)
{
for(int temp=0;temp<3;temp++)
{
for(int temp2=0;temp2<mapX;temp2++)
delete[] grid[temp][temp2];
delete[] grid[temp];
}
delete[] grid;
}


----------------
- Pouya / FOO!!!
***CENSORED***

Topic Locked

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

Sign in to reply to this topic.