What is the dynamic initialization of objects? Why is it needed? 

Dynamic initialization of objects means to provide the initial values to an object at runtime. we can provide different initialization formats of data for an object at runtime using dynamic initialization of objects. We can use various data types like int, float or char depending upon our need for the same object created. This provides the flexibility of using different format of data at runtime depending upon the situation.
Dynamic initialization of objects can be accomplished using constructor overloading. 

An example to understand dynamic initialization of objects: 


#include<iostream>
using namespace std;
class A
long a;
int b;
float c;
public:
A()
{
}
A(long x, int y, float z=0.15);
A(long x, int y, int z);
};

Here in this example class A uses three overloaded constructors. The parameter values to these constructors are provided at run time. One can input in any of the form to create object of this class.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: