C++ Program Using Constructor and Destructor
This is an object oriented programming in c++ to create database of the following items:
1. Name of the student
2. Roll number of the student
3. Height of the student
4. Weight of the student
Constructor has the same name as the name of the class. Constructors are automatically called as soon as the object of the class is created. Constructor is also used to initialize the object of that class.
Destructor is the opposite of constructor. Destructor is used to destroy the objects created by constructor. Destructor also has the same name as of the class. There will be only one destructor in a class.
Char name ;
Float height, weight;
Strcpy (name, “ram”);
Void display ()
Cout<<”\n name :”<< name;
Cout<<”\n roll no”<<roll;
~ Student ()
Cout<<”\n destroying object”;
Void main ()
Obj. Student ();
The above program is designed in-order to store the data’s of student. The class named ‘student’ has been declared in the program. This program uses constructor and destructor.
- Destructor In C++ Destructor in c++ It is used o destroy the object...
- Constructor in C++ Constructor in C++ Constructor is a member function with the...
- Array Of Class Object Array of class objects Array is a collection of similar...
- Array of class objects Array of class objects and single inheritance A program consisting...
- Virtual Destructor Virtual destructor C++ standard does not allow declaration of destructor...