Hi Chris,

On 17 December 2015 at 20:43, Chris Cleeland <chris.cleeland@gmail.com> wrote:


On Thu, Dec 17, 2015 at 1:38 PM, Ian Bruntlett <ian.bruntlett@gmail.com> wrote:

If a member function finishes the job and frees the resources, have that member function modify the object's member variables so the destructor can recognise that the resources have been freed and it doesn't need to do anything about those resources.

This approach is called RAII and see this page:-
https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization

"delete this" sounds more like Resource Suicide and not RAII.
Yes, the original question was this:-
"In my code there are objects created, which delete themselves.  They can do it in the constructor, or later in some function.  This is ugly, and I'm getting some wierd behaviour, probably because of this bad design."

Then another question was brought up, which indicated resource suicide. I've got to go offline now so I can't help much more than I have done.

BW,


Ian

--
-- ACCU - Professionalism in programming - http://www.accu.org
-- My writing - https://sites.google.com/site/ianbruntlett/