No. Try using
realloc(). You need to include
malloc.h for it. I'm not sure if it works with the
new operator. In that case, you'll need to allocate memory like this (someone else correct me if I'm wrong, please):
Code:
#include <malloc.h>
#include <iostream>
using namespace std;
.
.
.
int *myArray;
int arrSize = 10;
//use calloc to allocate arrays, and malloc to allocate single blocks,
//like for classes and structs. I'd use the new operator for classes,
//though.
myArray = (int *)calloc(arrSize,sizeof(int));
if(myArray == NULL)
cout << "Allocation failed." << endl;
.
.
.
//reallocate:
arrSize = 15;
int *temp = (int *)realloc(myArray,arrSize);
if(temp == NULL)
cout << "Reallocation failed." << endl;
else
myArray = temp;
.
.
.
free(myArray);