Whenever value passed to a parameterized constructor is provided at runtime it is known as dynamic constructor
#include<iostream.h>
#include<conio.h>
class abc
{
int a,b;
public:
abc()
{
a=0;
b=0;
}
abc(int x,int y)
{
a=x;
b=y;
}
void show()
{
cout<<"a= "<<a<<endl<<"b= "<<b<<endl;
}
};
void main()
{
clrscr();
int l,m;
cout<<"Enter two no." <<endl;
cin>>l>>m;
abc ob1,ob2(l,m);//dynamic constructor
ob1.show();
ob2.show();
getch();
}
In main function l & m will be initialized at runtime.
No comments:
Post a Comment