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
Objective of this Program: (a) To learn more about modularization of a program into independent modules, (b) To use arrays in a program, (c) To get some experience with us


Write C code for a program that implements a digital clock (HH:MM:SS). The clock includes a two-digit hour indicator HH (00-23), a two-digit minute indicator MM (00-59), and a t



Study the following table used to compute the tax payable by employees in certain organization   Gross Pay                                  Fewer than Three             Three

Create an array of Strings and fill it with some interesting text, such as vacation destinations, album names, or weapon names from a CRPG. Display three elements of the array on t

The program must use the file named on the command line as its input file. Suppose the program is named pdbtool. Then if the user types pdbtool 1A36.pdb the program must read the d

a program to find the area under curve y=f(x) between x=a and x=b,integrate y=f(x) between the limits of a and b.

Define a structure to store roll no, name and marks of a student. b) Using the structure of Q2. a), above write a ''C'' program to create a file "student.dat". There must be one r