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
Write a program that illustrate  Macros with Arguments? Macros is able to also have arguments, just as functions can. #define AREA(x)(3.14*x*x) Then at any time the prepr

Use 16 digit credit card numbers that contain 15 digits an 1 check digit. The format of the card number consists of the 15 digits followed by the check digit. The check digit is co

How do I allocate multidimensional arrays by new? A: There are several ways to do this, based on how flexible you wish the array sizing to be. On one acute, if you know all the

Aim: Write a program of multipication using inline function class Multiply {           int x,y;           public:           void getdata();           inline calc


How do you know that your class requires a virtual destructor? A: If at least your class has one virtual function, you must make a destructor for this class virtual. It will let

Within software engineering, software is very rarely written by a single software engineer. Usually a team of engineers write a program; therefore a formal structural design approa

Explain  U s e r - D e f i n e d D a t a T y p es? C has Union and Structure as user-defined data types.  C++ has class which looks like structure with a


removing jewel from a necklace