[ECOS] A C++ question regarding the delete operator
Chris Sekula
chriss@turnpikeglobal.com
Tue Jan 1 08:00:00 GMT 2002
Yes, after looking through the code a bit more thoroughly, I believe
that memory had been allocated in another method when the pointer was
created.
However, I'm still curious as to what may happen if 'delete' is called
on a pointer that is created locally without the 'new' operator ever
being invoked.
Any thoughts?
Thanks,
CHRIS.
-----Original Message-----
From: Rosimildo da Silva
Sent: Mon 12/31/2001 5:10 PM
To: Chris Sekula; ecos-discuss@sources.redhat.com
Cc:
Subject: Re: [ECOS] A C++ question regarding the delete operator
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?
Chris,
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.
Rosimildo.
More information about the Ecos-discuss
mailing list