C
Chris
say I have an class like this:
----------------------------------------
class grid {
int** GRID;
public:
grid() {
GRID = new int* [34];
for (int i=0; i<34; i++)
GRID = new int [34];
}
~grid() {
for (int i=0; i<34; i++)
delete [] GRID;
delete [] GRID;
}
};
----------------------------------------
is it safe to do this?
----------------------------------------
grid* cube = new grid [34];
delete [] cube;
----------------------------------------
I guess my question is, when you de-allocate something, does it do what
the destructor says to do?
I know somebody is going to tell me to use vectors because they're
safer. While I agree with you, know that this question is only to help
me gain a deeper understanding of how it works.
Thanks for any help!
----------------------------------------
class grid {
int** GRID;
public:
grid() {
GRID = new int* [34];
for (int i=0; i<34; i++)
GRID = new int [34];
}
~grid() {
for (int i=0; i<34; i++)
delete [] GRID;
delete [] GRID;
}
};
----------------------------------------
is it safe to do this?
----------------------------------------
grid* cube = new grid [34];
delete [] cube;
----------------------------------------
I guess my question is, when you de-allocate something, does it do what
the destructor says to do?
I know somebody is going to tell me to use vectors because they're
safer. While I agree with you, know that this question is only to help
me gain a deeper understanding of how it works.
Thanks for any help!