Boost logo

Boost Users :

Subject: Re: [Boost-users] how to help an object to delete itself the boost way
From: Ireneusz Szcześniak (irek.szczesniak_at_[hidden])
Date: 2015-12-17 14:22:57


My objects can delete themselves in two cases:

1) in the constructor, when they realize they cannot handle the job
they are supposed to do, because they cannot allocate the resources
required,

2) in a member function, when they finish their job and free their
resources.

I guess that in the constructor I should throw an exception, instead
of trying to delete the object. So the first case is resolved.

The second case is tricky. I could keep a container of smart pointers
to my objects, and delete objects by removing the pointer from the
container. The problem is that this removal should be initialized by
the object itself, i.e., in a member function a pointer is removed
from the container, but then that function operates on an object that
was just deleted.

Irek

W dniu 17.12.2015 o 19:20, John Maddock pisze:
>
>> 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.
>>
>
> I'm at a loss to understand how an object can possibly delete itself
> in it's own constructor...?
>
> Maybe you were looking for smart pointers to manage object lifetime?
>
> John.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net