#include<iostream.h>
#include<conio.h>
int c=0;
class demo
{
private:
                int x;
                demo()
                                {
                                if(c<=3)
                                                {
                                                cout<<"Private Default Constructor Is Executed"<<endl;
                                                x=10-c;
                                                cout<<"C = "<<c<<endl;
                                                cout<<"X = "<<x<<endl;
                                                ++c;
                                                demo();               //Recursive Constructor Call
                                                }
                                }
public:
                demo *func()
                                {
                                return (new demo());
                                }
};
void main()
{
                clrscr();
                demo *d=NULL;
                d=d->func();
                getch();
}

174

Advertisements