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

We want Guys For Job in Gaming Tracks Company for a mobile game developing Project Description: I want a team of game developers for life-time as mobile dev team in my compan

make a marksheet of 2 student with 5 subject

Problem : Change to palindrome A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your ta

The new and delete operators The C language has explained library functions- malloc() and free() for dynamic allocation and de-allocation of memory. C++ gives yet another appro

Create a pseudocode in getting Calendar Quarter. The program should identify which quarter falls the given date. Note: Consider the date format DDMMYYYY.

Implement the search property from catalogue menu option.  After selecting this option the user should be asked to specify the property using the following sub-menu: 1. Specif

What is inheritance? Class, the vehicle, which is used to execute object-oriented concepts in C++, has given a new dimension to this idea of reusability. Many vendors now offer

create algorithm for doubly link list using c data structure

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