Home > Backend Development > C++ > Is Using 'delete this' in C Ever Permissible?

Is Using 'delete this' in C Ever Permissible?

Patricia Arquette
Release: 2024-12-29 09:14:09
Original
391 people have browsed it

Is Using

Suicide in C : Can "delete this" be Permitted?

In C , the use of "delete this" can arise as a tempting option when a class instance aims to self-terminate. However, this practice is not without controversy and has fueled discussions among programmers. Is it permissible to employ "delete this" under specific circumstances?

One such instance involves the deletion of an object designated by the "this" pointer after its use in a controller to switch to a different module. The controller, through the "setWorkingModule" function, assigns a new pointer to the module in focus. Given this change, the intention arises to dispose of the previous module pointed to by "this."

In this scenario, the C FAQ Lite provides valuable guidance:

  • [FAQ Entry on Suicide in C ](https://isocpp.org/wiki/faq/freestore-mgmt#delete-this)

The FAQ asserts that "suicide" (i.e., "delete this") is permissible under certain conditions:

"As long as you're careful, it's OK for an object to commit suicide (delete this)."

The above is the detailed content of Is Using 'delete this' in C Ever Permissible?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template