What if one can''t wrap the local in an artificial block?, C/C++ Programming

Assignment Help:

What if one can''t wrap the local in an artificial block?


Related Discussions:- What if one can''t wrap the local in an artificial block?

Largest clique, find largest clique present in graph

find largest clique present in graph

Write a program that illustrate union declaration, Write a Program that ill...

Write a Program that illustrate union declaration? A C program encloses the following union declaration: union id { char color[12]; int size; } shirt, blouse; At this

Single string programme, write a programme that allows a user to enter 5 di...

write a programme that allows a user to enter 5 distinct words and returns them as a single string

Boolean functions and simple logic design, The digital signal is one which ...

The digital signal is one which only consists of two states i.e. logic '1'   (+5 volts) and logic '0' (0 volts). Various electronic blocks use logic and these form the basis of a m

Decodethecode, how to decode the numerals to string..

how to decode the numerals to string..

Program to display stock containing item code, THIS PROGRAM IS TO DISPLAY A...

THIS PROGRAM IS TO DISPLAY A STOCK CONTAINING ITEM CODE,ITEM NAME,PRICE AND ANOTHER STOCK WITH CODE & QUANTITY AND DISPLAY COMPLETE INFORMATION #include #include #include

CptS 121 Program Development & Design program design in C, Write a program...

Write a program that performs character processing on 10 characters read in from a file, and writes the results to output files. Do NOT use loops or arrays to solve this problem. N

Destructor, Destructor: The purpose of destructor is to free the memory...

Destructor: The purpose of destructor is to free the memory when the compiler memory is reduced or not enough to execute certain program. Sometimes there may several objects op

ARRAY, A PROGRAM TO CALCULATE AREA OF TRIANGLE

A PROGRAM TO CALCULATE AREA OF TRIANGLE

3/15/2013 5:35:15 AM

What if one can''t wrap the local in an artificial block?

A: Mostly time, one can limit the lifetime of a local via wrapping the local in an artificial block ({...}). But if for some cause you can''t do that, add a member function which has a similar effect as the destructor. Although do not call the destructor itself!

For instance, in the case of class File, you may add a close() method. The destructor typically will simply call this close() method. Note down that the close() method will have to mark the File object so a subsequent call won''t re-close an already-closed File. For example it might set the fileHandle_ data member to some nonsensical value like -1, and it may check at the starting to see if the fileHandle_ is already equal to -1:

 

class File {

public:

void close();

~File();

... private:

int fileHandle_; // fileHandle_ >= 0 if/only-if it''s open

};

File::~File()

{

close();

}

void File::close()

{

if (fileHandle_ >= 0) {

...insert code to call the OS to close the file... fileHandle_ = -1;

}

}

Note down that the other File methods might also have to check if the fileHandle_ is -1 (that mean., check if the File is closed).

Note down  also that any constructors that don''t actually open a file should set fileHandle_ to -1.

 

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