How to delete a non dynamic array

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];
You don't delete it. It will be cleaned up when your program ends.
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...
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.
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
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
so there isn't a way to delete it? Should i create and array in oneother way so i can delete it later?
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.
ok i wish my teacher is ok with it. thank you a lot m8.
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.