Artificial block, C/C++ Programming

Assignment Help:

What if I cannot wrap the local in an artificial block? need help on Artificial Block in c++.

 


Related Discussions:- Artificial block

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

#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

[email protected], Write a program to find the area under the curve y =...

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

What are the different types of endless loops, What are the different types...

What are the different types of endless loops? An endless loop can be of two types: i.) A loop that is intentionally designed to go round and round until the condition withi

What''s the deal along with operator overloading?, A: It let you to provide...

A: It let you to provide an intuitive interface to users of your class, as well as makes it possible for templates to equally work well with classes and built-in/intrinsic types.

Matrix transposition cipher, write a C rpogram that can display the transpo...

write a C rpogram that can display the transpose form of a ciphertext matrix.Prompt users to provide row and coloumn number of matrix.Then user will input plaintext and the program

Determine the size of operator, The size of () operator This is a pseud...

The size of () operator This is a pseudo-operator given by the language, which returns the number of bytes taken up by a variable or data type. The value returned by this opera

Define bitwise-and operator, Define Bitwise-AND Operator: &:? The bitwi...

Define Bitwise-AND Operator: &:? The bitwise-AND operator (&) compares every bit of its first operand to the corresponding bit of its second operand. If both bits are 1 the mat

Explain the goto statement, The goto statement This statement can be us...

The goto statement This statement can be used to branch to another statement of the program. This is rarely used as it violates the principle of structured programming. Though

Program to show the ascii value of characters, Program to show the ascii va...

Program to show the ascii value of characters: int main() {                 int one_char;                 cout                 one_char = getch();

C++ Assignment Help me , Write a c++ program that contain the following fun...

Write a c++ program that contain the following functions : 1) Function Quality_Point that takes one int argument (student_average) and return ‘A’ if the student_average between 90-

Oscar

2/13/2013 2:08:08 AM

Artificial block

Several times, you can limit the lifetime of a local by wrapping the local in an artificial block ({...}). But if for a number of reasons you cannot do that, add a member function that has a similar effect as the destructor. But do not call the destructor itself!  

For example, in the case of class File, you might add a close() method. Usually the destructor will simply call this close() method. Note that the close() method will need 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 might check at the beginning 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 that the other File methods may also need to check if the fileHandle_ is -1 (i.e., check if the File is closed).  Note also that any constructors that don''t actually open a file should set file Handle_ 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