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

Dynamic initialization of objects and dynamic constructor, Dynamic Initiali...

Dynamic Initialization of objects: It is initializing the objects by passing the valued to the constructor from the user input or other means.   Through cin operator a value

Stack over flow for sun sparc, Please use C or C++ to write your programs. ...

Please use C or C++ to write your programs. Our homework will focus on SUN sparc machines because to exploit x86 stack-overflow is too easy. This is not just a programming assignme

When should you employ multiple inheritance?, Q: When should you employ mul...

Q: When should you employ multiple inheritance? A:There  are  three  acceptable  answers:-  "Rarely," "Never," and  "while  the  problem  domain cannot be modeled accurately any

Pro, i need to do my home work

i need to do my home work

Compiler design, Compiler Design - Limit In The Method Instructions

Compiler Design - Limit In The Method Instructions

How does c++ help with the tradeoff of security vs.usability, A: In C, enca...

A: In C, encapsulation was completed by making things static in a compilation unit or module. It prevented another module from accessing the static stuff. (Incidentally, now static

C++, 2. Write C++ code for calculating the time table

2. Write C++ code for calculating the time table

Object Oriented Programming , You are required to give C++ implementation o...

You are required to give C++ implementation of following classes: 1. PropertyCategories 2. Plot 3. Flat 4. House Following is the description of all data member and member funct

Algorithem, algorithem of compound interest

algorithem of compound interest

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