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

Assignment Help:

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?

 


Related Discussions:- If i wish a local to "die" before the close} of the scope

Computes the area of a circle of radius r, (a) Write a procedure called (ar...

(a) Write a procedure called (area-of-rectangle h w) that computes the area of a rectangle of height h and width w. (b) Write a procedure called (area-of-circle r) that computes

Explain function overloading, F u nction overloading: Functions can b...

F u nction overloading: Functions can be defined with same name.  Depending upon the type of argument passed the function will perform.  This is known function overloading

Change to palindrome, A palindrome is a string that reads the same from the...

A palindrome is a string that reads the same from the both the ends. Given a string S convert it to a palindrome by doing character replacement. Your takes is to convert S to palin

Define some features of static storage class in c program, Define some feat...

Define some features of static storage class in c program? The features of a variable defined to contain a static storage class are as follows. Storage - memory Default

Program for greatest common divisor – c++ program, Greatest Common Divisor ...

Greatest Common Divisor (GCD) - The greatest common divisor (GCD) of two integers is the largest integer that will evenly divide both integers. The GCD algorithm involves intege

Area under curve, Write a program to find the area under the curve y = f(x)...

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.

C program for function of divider , C Program for FUNCTION OF DIVIDER ...

C Program for FUNCTION OF DIVIDER int gcd(int , int); void main() {           int m=0,n=0,k=0;           clrscr();           printf("ENTER THE FIRST DIGIT: ");

Help, what is c++ ?

what is c++ ?

Explain the scope resolution operator, The Scope Resolution Operator( :: ) ...

The Scope Resolution Operator( :: ) Global variables are explained outside any functions and thus can be used by all the functions defined thereafter. However, if a global vari

3/15/2013 5:25:26 AM

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!

 

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd