In C++, is it possible to create a new array during program runtime? Specifically, suppose I have a data member in a class and the name of the variable is array, which is an array of size 10. Suppose during runtime I want a bigger array, can I do this without using pointers? Can I have a method as follows?
int[] expandCapacity(int currentCapacity) {
int [] arr = new int[currentCapacity*2];
currentCapacity*=2;
return arr;
}
Why can't I use this method to expand the current array's capacity by saying:
currentCapacity = 10;
array = expandCapacity (currentCapacity);
If this works, there would be no need to use pointers. I feel like I'm missing something crucial here. I'd appreciate if you could point out what I am missing.