[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: question about "new" and "delete" ?
From: |
jack |
Subject: |
Re: question about "new" and "delete" ? |
Date: |
13 Mar 2005 12:01:10 -0800 |
User-agent: |
G2/0.2 |
I just try your method,it can work. thanks
Mike - EMAIL IGNORED wrote:
> 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.
Re: question about "new" and "delete" ?, Thomas Maeder, 2005/03/06