In C++, a Dynamic constructor is basically used to allocate memory to the objects at run time. the memory is allocated at run time using the 'new' operator.
In addition, by using this constructor, objects can be dynamically initialized.
Example:
#include <iostream.h>
#include <conio.h>
class dyncons
{
int * p;
public:
dyncons()
{
p=new int;
*p=10;
}
dyncons(int v)
{
p=new int;
*p=v;
}
int dis()
{ return(*p);
}
};
void main()
{
clrscr();
dyncons o, o1(9);
cout<<"The value of object o's p is:";
cout<<o.dis();
cout<<"nThe value of object 01's p is:"<<o1.dis();
getch();
}