In C we used malloc(), free()
, but in C++ youare using new, delete
, but in C we also have realloc
, which will alloc the new block and copy the old data (common minimum) and then free the old data bock. So what is the C++ version of that? I can write my own of course, but is there a builtin thing?
main() {
int i; char *x = malloc(3);
x[0] = 10;
x[1] = 20;
x[2] = 30;
realloc(x, 4);
x[3] = 40;
for (i = 0; i < 4; i++) printf("%i
", x[i]);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…