Is it legal for a member function to say delete this?, C/C++ Programming

Assignment Help:

Is it legal for a member function to say delete this?

A: As long as you're cautious, it's OK for an object to delete this.

Here's how I define "cautious":

You have to be absolutely 100% positive sure that this object was allocated through new (not through new[], nor through placement new, nor a local object on the stack, nor a member of another object nor a global,; but by plain ordinary new).

You have to be absolutely 100% positive ensure that your member function will be the last member function invoked on this object.

You have to be absolutely 100% positive ensure that the rest of your member function (after delete this line) doesn't touch any piece of this object (by including calling any other member functions or touching any data members).

You have to be absolutely 100% positive ensure that no one even touches the pointer itself after the delete this line. In other terms, you have to not examine this, compare this with another pointer, compare this with NULL, print this, cast this, do anything with this.

Of course the usual caveats apply in cases where your this pointer is a pointer to a base class while you don't have a virtual destructor.

 


Related Discussions:- Is it legal for a member function to say delete this?

C program to swap the two values, Program is to swap the two values which a...

Program is to swap the two values which are enter by user: Program is to swap the two values which are enter by user through the function with values changed using pointers

Chapter 21, Test scores solution help. Three member variables

Test scores solution help. Three member variables

Coding, dispaly the last ant on rod

dispaly the last ant on rod

Asset pricing project, In the final project assignment you are asked to dev...

In the final project assignment you are asked to develop an OOP C++ class hierarchy for derivative pricing, using the binomial tree and Black-Scholes option pricing methods. You wi

Programming, write a program that can accept numbers and perform all the fo...

write a program that can accept numbers and perform all the four arithmetic operation

Decode the code, Smugglers are becoming very smart day by day. Now they hav...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

#Program, Write a program that accepts two real numbers from a user and a s...

Write a program that accepts two real numbers from a user and a select code. If the entered select code is 1, have the program add the two previously entered numbers and display t

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd