+ 3
Why we use dynamic constructor in c++?
2 Antworten
+ 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....
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.