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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -