Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > destruction of already destructed pointer variable when copying anobject - abort error

Reply
Thread Tools

destruction of already destructed pointer variable when copying anobject - abort error

 
 
suresh
Guest
Posts: n/a
 
      09-15-2010
On Sep 15, 1:54*am, James Kanze <james.ka...@gmail.com> wrote:
> On Sep 13, 9:03 pm, suresh <suresh.amritap...@gmail.com> wrote:
>
> > On Sep 10, 9:24 pm, Garrett Hartshaw <gharts...@gmail.com> wrote:
> > > I'm no expert, but I would say that a smart pointer (e.g.
> > > std::tr1::shared_pointer) would probably be your best choice.

> > Garret this means that I can avoid having a destructor if I use the
> > shared_pointer right?

>
> No. *It means that you don't have to write one yourself. *You
> still have a destructor; it's just that the compiler generates
> the correct one automatically.


or rather as I understood lately, when a shared_ptr is used, instead
of calling delete in the destructor, one calls reset() which will
reset the reference count and when it becomes zero, it will be
automatically deleted. Am I right?
suresh
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      09-16-2010
On Sep 16, 12:53 am, suresh <suresh.amritap...@gmail.com> wrote:
> On Sep 15, 1:54 am, James Kanze <james.ka...@gmail.com> wrote:


> > On Sep 13, 9:03 pm, suresh <suresh.amritap...@gmail.com> wrote:


> > > On Sep 10, 9:24 pm, Garrett Hartshaw <gharts...@gmail.com> wrote:
> > > > I'm no expert, but I would say that a smart pointer (e.g.
> > > > std::tr1::shared_pointer) would probably be your best choice.
> > > Garret this means that I can avoid having a destructor if I use the
> > > shared_pointer right?


> > No. It means that you don't have to write one yourself. You
> > still have a destructor; it's just that the compiler generates
> > the correct one automatically.


> or rather as I understood lately, when a shared_ptr is used, instead
> of calling delete in the destructor, one calls reset() which will
> reset the reference count and when it becomes zero, it will be
> automatically deleted. Am I right?


No.

If the compiler generates the destructor, it calls the
destructor of all non-static members. If you write
a destructor, the compiler adds code to it to call the
destructor of all non-static members. The destructor of
shared_ptr does the right thing. (For its defined
semantics---I'm still not convinced that those semantics
correspond to your needs. More likely, you shouldn't be
dynamically allocating anything to begin with.)

--
James Kanze
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
an error message- Object reference not set to an instance of anobject. Montezuma's Daughter ASP .Net 4 07-19-2008 05:58 PM
I.E. jscript error: 'document.getElementById(...)' is null or not anobject. Elizabeth.Lattanzio@gmail.com Javascript 3 01-03-2008 03:43 PM
Abort trap - Fatal Python error: GC object already tracked p.lavarre@ieee.org Python 1 07-10-2007 05:53 PM
Local objects in function not destructed on exception? Robbie Hatley C++ 4 09-25-2005 03:41 PM
My Hard drive just self-destructed... Terry Olsen Computer Support 4 05-15-2004 01:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57