Dynamic constructor in C++ Example


Dynamic constructor in C++ Example


/********************************************************************************************************
*************Designed and Developed by V2Geeks******************************************
********************************************************************************************************/

// Example of 
Dynamic constructor To INITIALIZE ARRAY
#include<iostream.h> #include<conio.h> class Test { public: int id; int a[ ]; Test()// default constructor { } Test(int x) { id=x; } void get() { int i; for(i=0;i<id;i++) a[i]=i+1; } void display() { int i; for(i=0;i<id;i++) cout<<a[i] ; } }; void main() { Test A(10); //Now array can be changed according to requirement A.get(); //it will print 1 to 10 A.display(); //it will print 1 to 10 getch(); }
Reactions: