If i wish a local to "die" before the close} of the scope, C/C++ Programming

What if I wish a local to "die" before the close} of the scope wherein it was created? Can I call a destructor on a local if I want to?

 

Posted Date: 3/15/2013 5:25:01 AM | Location : United States





What if I wish a local to "die" before the close} of the scope wherein it was created? Can I call a destructor on a local if I want to?

A: No

Imagine the (desirable) side effect of destructing a local File object is to close the File. Suppose now you have an object f of a class File and you wish File f to be closed before the end of the scope (that means }) of the scope of object f:

void someCode()

{

File f;

...insert code that must execute while f is still open... We wish the side-effect of f''s destructor here!

...insert code which should execute after f is closed...

}

There is a simple solution to this dilemma. However in the mean time, remember: Do not call the destructor explicitly!

 

Posted by | Posted Date: 3/15/2013 5:25:26 AM


Related Discussions:- If i wish a local to "die" before the close} of the scope, Assignment Help, Ask Question on If i wish a local to "die" before the close} of the scope, Get Answer, Expert's Help, If i wish a local to "die" before the close} of the scope Discussions

Write discussion on If i wish a local to "die" before the close} of the scope
Your posts are moderated
Related Questions

Project Description: Project is related indexing data related some data structure. I need to share all information related project later if i contact any body Skills required

Why many companies are switching their current business language to PHP? Where PHP basically used? PHP is rapidly gaining popularity and numerous companies are switching their

In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color. Fill the other elements in the board, suc

the program that solve the efficiency of otto cycle

Write a program that writes your name on the monitor ten times. Write this program three times, once with each looping method.

what is a variable

Define the following Window class : - integer  data members, width and height - a constructor  that accepts two integer  parameters  (width followed by height) and uses them to ini

Many human diseases could be controlled by the knowledge of the gene’s structure and pattern. The human gene could be represented by four nucleotides. Each nucleotide is represente

Question: (a) A bank has four types of accounts with annual interest rates as follows: Savings 8% Savings with Cheque Book 5% Current 4% Fixed deposits 10% Using