I have made a code in which i am creating array of objects using new.I am extending the array by another new keyword and last index of previous array like following.Its working fine(The constructor is printing "a" number of times the net index). But i dont know is it safe or not? My main motive is to make a dynamic array but i cant use malloc because it dows not call constructors.So i am using new. But idont know how to reallocate memory after using new. If i use realloc then the program is not giving any error but realloc is not calling the constructor.
Summary:->Just want to call constructor while reallocating memory.
I have given the image of my code
class xy { unsigned x[10],y[10],counter; public: xy() {counter=0;} void setxy(unsigned a,unsigned b) {x[counter]=a;y[counter]=b;counter++;} void printxy() {for(unsigned i=0;i<counter;i++)cout<<"="<<x[i]<<"^3+"<<y[i]<<"^3";} }; class unitcell { unsigned long long value_cube,hasharr_len; xy* hasharr; unsigned long long* r_numberindexes; unsigned rarraylen; public: unitcell() {cout<<"a";} unsigned long long gethasharraylen() {return hasharr_len;} }; int main() { unitcell *a=new unitcell[3]; unitcell *b=a+3; b=new unitcell[3]; }