1. How do I call the destructor for a single object?
Within an arrangement, you can do estudiante[3].~alumno( );
2. How do I destroy the whole arrangement?
As you said, the fix is destroyed when you exit the function, automatically. Before said destruction , they are invoked, one by one, the destructors of the objects contained in the array.
If you want to be able to destroy it when it pleases you, you have to use dynamic memory:
alumno *estudiante = new alumno[10];
...
delete[] alumno;
If you use this last formula, dynamic fixes , remember that it is your responsibility to destroy them by doing delete[]
. The compiler totally disregards them. That is, they are not destroyed or released when leaving the function.
3. If I delete an object, the data remains blank? or the object box disappears? (So if the size of the array is 10, it will go down to 9?)
If the instances are within an array , neither the array nor the data changes. Everything remains as it is when the destructor of the class involved ends.
If the destroyer does nothing, the memory remains as it was. Of course, the number of elements in the array does not change .
Think that, from the compiler's point of view, a array is nothing but a block of memory . Once assigned , it does not change in size (unless we change it explicitly).
Care with what you do. By logic, if you first call the destructor of an object, and then do the delete
of the complete array, the destructor will be called again . It is up to you to check the logic of your program.