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:
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!