Here is an simple example to demonstrate the use of dynamic constructor:
#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();
}
Output of above program :
algorithm please
ReplyDeletecan u please provide an algorithm 4 this program
ReplyDelete