+ 3

Why we use dynamic constructor in c++?

20th Apr 2021, 6:38 AM
𝖆𝖙.𝖚𝕷
𝖆𝖙.𝖚𝕷 - avatar
2 ответов
+ 1
A dynamic constructor is nothing just fancy name ...just see class A { private: int *ptr; public: A(int val) { ptr=new int; *ptr=val; } ~A() { delete ptr; } } here {A} is a dynamic constructor it's speciality is...that it is allocating memory for the object ... NOTE : for the object not of the object ... In this code {A} a constructor which is allocating memory(dynamically) pointed by pointer {ptr} which is object's member... i.e. {A} is allocating memory for the object or the memory which is used by the object .... So it's a DYNAMIC CONSTRUCTOR....
21st Apr 2021, 5:23 PM
000
000 - avatar
0
To dynamically allocate the object at the run time. https://tutorialink.com/cpp/dynamic-constructor.cpp#:~:text=Dynamic%20constructor%20is%20used%20to,can%20dynamically%20initialize%20the%20objects.
20th Apr 2021, 8:40 AM
KUMAR SHANU
KUMAR SHANU - avatar