How to delete a non dynamic array

Jan 19, 2012 at 3:27pm
How can i delete a non dynamic array?
i tried delete array[]; but it's for dynamic arrays right?
this is the code :/
1
2
3
4
5
6
7
8
static const int MAXSIZE=20;
class char_and_priority
{
    public:
    char character;
	int priority;
};
char_and_priority array[MAXSIZE];
Jan 19, 2012 at 3:33pm
You don't delete it. It will be cleaned up when your program ends.
Jan 19, 2012 at 3:35pm
My exercise sais that there is a delete option. When the user chooses it i have to call the method void delete()
which deletes the array...
Jan 19, 2012 at 3:58pm
You can't free the memory of the array. Maybe the exercise mean you should somehow clear the data by setting everything to zero or if you have a size variable to keep track of the size maybe that should be set to zero. I don't know wha tthe exercise is about so your guess is probably better than mine.
Jan 19, 2012 at 4:39pm
The exercise says when user choose exit ,the program deletes the pile and then it is finished. My exercise is about a pile(max).(pile in a form of an array)
Last edited on Jan 19, 2012 at 4:41pm
Jan 19, 2012 at 4:43pm
you CAN control when will be automatic objet deleted/freed up like this:

1
2
3
4
5
6
7
8
int main()
{
      int x;
      {
            int y = 4;
      } // Y DIES HERE
       return 0;
} // X DIES HERE 


but you can't call delete on automatic object!
Last edited on Jan 19, 2012 at 4:43pm
Jan 19, 2012 at 6:40pm
so there isn't a way to delete it? Should i create and array in oneother way so i can delete it later?
Jan 19, 2012 at 6:46pm
The exercise says when user choose exit ,the program deletes the pile and then it is finished


When the program finishes, everything is deleted and then it is finished. This is usually achieved like this:

1
2
3
4
5
6
int main()
{
  // all your program code...

  return 0;
}


When you return from the main function (i.e. when your program exits), everything is deleted.
Jan 19, 2012 at 6:51pm
ok i wish my teacher is ok with it. thank you a lot m8.
Jan 19, 2012 at 7:37pm
so there isn't a way to delete it? Should i create and array in oneother way so i can delete it later?


Acctualy you can :D

1
2
3
4
5
6
7
8
int main()
{
    int a;
  
   // now delete a!!
#pragma deprecated a
   return 0;
}
Topic archived. No new replies allowed.