Using the delete operator on an object deallocates its memory. If pointer refers to an array, place empty brackets ( ) before pointer: int* set = new int The new and delete operators can also be used for built-in types, including arrays. For more information, see The new and delete Operators. This provision means that, when new returns 0 on failure, deleting the result of a failed new operation is harmless. You can, however, use delete on a pointer with the value 0. Using delete on a pointer to an object not allocated with new gives unpredictable results. For example: CDialog* MyDialog = new CDialog The delete operator has a result of type void and therefore does not return a value. The cast-expression argument must be a pointer to a block of memory previously allocated for an object created with the new operator.
0 Comments
Leave a Reply. |