Every one who has seen any movie of the Mission Impossible franchise would remember the unique way of starting every mission.
You Tube link to the scene (58 seconds) :
|Code Basics, C Plus Plus|
Now what happens after the message is over?
The last words in the message are always – “This message will self-destruct in 5 seconds.”
A Class Constructor is a special member function of a class that is executed whenever we create new objects of that class,
Exactly like the message in the movie, which automatically starts after scanning the retina or finger print.
A constructor will have exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for initializing the values for member variables of the class.
A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class,
Exactly like the message’s self-destructio
A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc.
using namespace std;
void setLength( double len ); // Function 1 Declaration
double getLength( void ); // Function 2 Declaration
Line(); // This is the constructor declaration
~Line(); // This is the destructor declaration
// Member functions definitions including constructor
cout << "Object is being created" << endl;
cout << "Object is being deleted" << endl;
length = len;
// set line length
cout << "Length: " << line.getLength(
Object is being created
Object is being deleted