help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about "new" and "delete" ?


From: Mike - EMAIL IGNORED
Subject: Re: question about "new" and "delete" ?
Date: Sun, 06 Mar 2005 14:05:55 -0500

Thomas Maeder wrote:
> 
> Mike - EMAIL IGNORED <m_d_berger_1900@yahoo.com> writes:
> 
> > To prevent the problem, I always follow
> > a delete by clearing the pointer:
> >
> >    delete [] a;
> >    a = 0;
> >
> > Your cout will then result in an immediate, and obvious
> > crash, which can then be debugged.
> 
> IMHO, better advice would be to not express ownership of a dynamically
> allocated resource through a "raw" pointer. Smart pointers are much
> better suited to that task.

I certainly agree with this comment on the value of smart pointers.  The
a = 0 technique is used within my smart pointers as insuance against
a coding error within the smart pointer itself.  However, there are
still
occasional situations in which a raw pointer is the best available plan.

Mike.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]