C++ Lecture-27
C++ Lecture-27
02
LECTURE 27
04
Today’s Agenda
01 Creating dynamic objects
05
05
Creating Dynamic Objects
Types of Objects
Enter l, b, h: 10 20 30
10, 20, 30
Enter l, b, h: 10 20 30
10, 20, 30
Enter Size?: 2
Enter l, b, h: 10 20 30
Enter l, b, h: 5 5 5
10, 20, 30
5, 5, 5
Types of Constructors
1. Default Constructor
4. Parametrized Constructor
5. Copy Constructor
7. Dynamic Constructor
Dynamic Constructor and Dynamic Destructor
In C++, a constructor is called DYNAMIC CONSTRUCTOR if it allocates memory for any class member
dynamically. In other words, we can say that, if inside the body of constructor we have used the keyword
"new" for allocating memory dynamically for a class member, then this constructor is called as DY-
NAMIC CONSTRUCTOR.
For Example
The class MyArray, which we discussed in the previous session had a constructor which was using
"new" for creating "dynamic integer array". Thus that constructor will be called as DYNAMIC
CONSTRUCTOR.
Similarly, if we have a destructor in our class which uses the keyword "delete" to dynamically destroy any
member of the class, then such a destructor will be called as DYNAMIC DESTRUCTOR.
For Example: The Destructor used in the class MyArray for destroying the dynamic array will be called as
Dynamic Destructor
Example
23, Amit
Process returned 0 (0x0) execution time : 0.075 s
Press any key to continue.
End of Lecture 27
For any queries mail us @: [email protected]
Call us @ : 0755-4271659, 7879165533
Thank you