в гайде к стандарту описано, слишком много НО, я бы не стал использовать, к тому же есть стандартные unique_ptr, shared_ptr, которые делают практически тоже самое, вот только безопасным методом и практически без оверхэда
https://isocpp.org/wiki/faq/freestore-mgmt#delete-this
а вообще прикольная штука, вроде автоматического сборщика мусора
As long as you’re careful, it’s okay (not evil) for an object to commit suicide (delete this).
Here’s how I define “careful”:
You must be absolutely 100% positively sure that this object was allocated via new (not by new[], nor by placement new, nor a local object on the stack, nor a namespace-scope / global, nor a member of another object; but by plain ordinary new).
You must be absolutely 100% positively sure that your member function will be the last member function invoked on this object.
You must be absolutely 100% positively sure that the rest of your member function (after the delete this line) doesn’t touch any piece of this object (including calling any other member functions or touching any data members). This includes code that will run in destructors for any objects allocated on the stack that are still alive.
You must be absolutely 100% positively sure that no one even touches the this pointer itself after the delete this line. In other words, you must not examine it, compare it with another pointer, compare it with nullptr, print it, cast it, do anything with it.
Naturally the usual caveats apply in cases where your this pointer is a pointer to a base class when you don’t have a virtual destructor.
Другие языки программирования и технологии
В каких случаях может быть хорошем решением применить delete this; ?
Похожие вопросы
- C++. В данном случае delete нужен?
- С++ Пожалуйста, объясните чайнику о операторах new и delete
- Операции new и delete. Операции new и delete нужна теори про данные операции.
- паскаль... строки...функция delete. не подскажете, почему в этой программе она не выполняется,что опять не так тут?(((
- С++ куча и new\delete
- PHP foreach($this->arFields as $name=>$structure)
- Как привязать, применить файл styles.css к html???
- EXCEL. Подскажите, какую форомулу можно применить?
- пишу crtl+alt+delete комп пишет отключён админом как включить обратно?
- Какой аналог delete из C++ в Java? Есть ли такой, подскажите пожалуйста....
Говорят, в com-объектах применяется...