]> git.mxchange.org Git - flightgear.git/commitdiff
from the C++ FAQ:
authorehofman <ehofman>
Thu, 22 May 2003 08:42:38 +0000 (08:42 +0000)
committerehofman <ehofman>
Thu, 22 May 2003 08:42:38 +0000 (08:42 +0000)
TITLE: Using delete [] versus delete

The extra "[]" warns the compiler that there is a whole array of objects here so that P's destructor must be called on each element of the array rather than just on P itself (which would be equivalent to the first element only).

src/GUI/dialog.cxx
src/GUI/menubar.cxx

index 5370e2a22c3f2dd406bc0b320336b237fd3d288a..a2e2fb8e364064ce0cfefc26dfcd9c1093db3e11 100644 (file)
@@ -134,7 +134,7 @@ FGDialog::~FGDialog ()
     for (i = 0; i < _char_arrays.size(); i++) {
         for (int j = 0; _char_arrays[i][j] != 0; j++)
             free(_char_arrays[i][j]); // added with strdup
-        delete _char_arrays[i];
+        delete[] _char_arrays[i];
     }
 
                                 // Delete all the info objects we
index 0164dd2d86a0796376ba377c2cb7503cf3532ea2..82724b2bc424f8f65598677341cb8dccdafe750c 100644 (file)
@@ -217,7 +217,7 @@ FGMenuBar::~FGMenuBar ()
     for (i = 0; i < _char_arrays.size(); i++) {
         for (int j = 0; _char_arrays[i][j] != 0; j++)
             free(_char_arrays[i][j]); // added with strdup
-        delete _char_arrays[i];
+        delete[] _char_arrays[i];
     }
 
                                 // Delete all the callback arrays
@@ -225,7 +225,7 @@ FGMenuBar::~FGMenuBar ()
                                 // plib.
     SG_LOG(SG_GENERAL, SG_INFO, "Deleting callback arrays");
     for (i = 0; i < _callback_arrays.size(); i++)
-        delete _callback_arrays[i];
+        delete[] _callback_arrays[i];
 
                                 // Delete all those bindings
     SG_LOG(SG_GENERAL, SG_INFO, "Deleting bindings");