// Dynamic constructor in C++
// Constructor can allocate dynamically created memory to the object .
// Thus,object is going to use memory region , which is dynamically created by constructor.
#include <iostream>
class Dummy{
private:
int a,b;
int *p; // pointer
Dummy() // Default constructor
{
a= 2;
b = 3;
p = new(int);
}
Dummy(int x,int y ,int z)//Dynamic constructor (because after call of constructor the dynamic
// variable is created and its address is store in instance variable pointer p.
{
a = x;
b = y;
p = new(int);
*p = z;
}
};
int main()
{
Dummy d1,d2(1,2,4);
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: