c++ - realloc() causes segmentation fault -
i have code:
perro **obj = null; obj = (perro**)malloc(10*sizeof(perro*)); (int = 0; < 10; i++) { obj[i] = new perrito((char*)"d",i); } realloc(obj,12*sizeof(perro*)); (int = 9; < 12; i++) { obj[i] = new perrito((char*)"d",i); } (int = 0; < 12; i++) { perrito *p; p = (perrito*)obj[i]; cout << p->getedad() << endl; }
when read object see memory dumped (segmentation fault) error. when comment out realloc
line , reduce last length item works normally, need use realloc
increase polifirmist object length.
obj = realloc(obj,12*sizeof(perro*));
pointer change after realloc!
Comments
Post a Comment