[ECOS] A C++ question regarding the delete operator

Rosimildo da Silva rosimildo@hotmail.com
Mon Dec 31 14:11:00 GMT 2001

From: "Chris Sekula" <chriss@turnpikeglobal.com>
To: <ecos-discuss@sources.redhat.com>
Sent: Monday, December 31, 2001 3:47 PM
Subject: [ECOS] A C++ question regarding the delete operator

> Recently, I came across some code for a linked list where a pointer to a
> structure is declared locally in a function and initialized. Later in
> the function, the 'delete' operator is used on the pointer, yet the
> 'new' operator was never used to allocate any memory on the heap.
> For example:
> void fun
> {
>      struct ListNode* temp;
>      temp = head    // head is a member of the Linked List class
>      ///  more code ///
>     delete temp;
> };
> Will there be any adverse affects if delete is used on the pointer
> although the new operator had never been invoked?


This is fine as long as the pointer "head" has been allocated using
"new" sometime in the past, peharps in another call when the 
linked list was created.


More information about the Ecos-discuss mailing list