Advertisements
Advertisements
Question
Answer the question after going through the following class.
class Book {
int BookCode ; char Bookname[20];float fees;
public:
Book( ) //Function 1
{ fees=1000;
BookCode=1;
strcpy(Bookname,"C++"); }
void display(float C) //Function 2
{ cout<<BookCode<<":"<<Bookname<<":"<<fees<<endl; }
~Book( ) //Function 3
{ cout<<"End of Book Object"<<endl; }
Book (intSC,char S[ ],float F) ; //Function 4
};
What is the use of Function 3?
Short Note
Solution
Function 3 is the destructor of the class.
- Destructor (function3) will free resources if any that the object may have acquired during its lifetime
- The destructor function removes the memory of an object which was allocated by the constructor at the time of creating an object. Thus frees the unused memory.
shaalaa.com
Is there an error in this question or solution?
Chapter 15: Polymorphism - Evaluation - Section - D [Page 258]