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

S

suresh

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
 
J

James Kanze

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top