Re: "delete this" question
On Nov 13, 6:04 am, owebee...@gmail.com wrote:
On Nov 13, 12:02 pm, WaterWalk <toolmas...@163.com> wrote:
On Nov 12, 9:10 pm, "Alf P. Steinbach" <al...@start.no> wrote:
...
I encountered "delete this" several times, so I decided to take a
close look at it. I don't think it's useful in practice....
"delete this" is commonly used in reference counted objects
(where the reference count is part of the object - sometimes
called intrusive reference counting).
I don't know that it's that common in this idiom. In this case,
you do have a natural owner outside of the class who can also
call delete; depending on how the class is designed, there can
even be advantages to doing so. (My RefCntPtr used a delete
this until I modified it to support conversions between derived
and base. This meant that the base having the counter couldn't
be a template, and thus didn't know the type of the class for
which it was reference counting. Since I didn't want to impose
a virtual destructor when inheritance wasn't involved, I moved
the delete out to the pointer, which did know the derived type.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34