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

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.

 

Posted Date: 3/19/2013 8:50:02 AM | Location : United States







Related Discussions:- Is it legal for a member function to say delete this?, Assignment Help, Ask Question on Is it legal for a member function to say delete this?, Get Answer, Expert's Help, Is it legal for a member function to say delete this? Discussions

Write discussion on Is it legal for a member function to say delete this?
Your posts are moderated
Related Questions
ABC Car Dealership needs your help to update the ordering system. This car dealer is selling four types of vehicles: Sedan, Truck, SUV, and mini Van. And each type of vehicle can h

Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation. If the given

Get Reverse Engineer to Linux game routine analysis Project Description: I want a fast and efficient reverse engineer with good knowledge of assembly x86 language, strong rev

Classify computer systems according to capacity. How they are different from computers according to the classification of technology. Provide comparative study also.

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation.

The purpose of this assignment is to familiarize you with the notion of encapsulation as well as some aspects of IP and ICMP. Write your programs in C or C++. They will be grade

Project Description: We are seeking online invoice OCR solution. That will help us to automate accounts payable function. User should be able to use the offered pdf file or s


padovan string for natural numbers program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : package test.padovanstring; public class Padov

What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than a