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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users