Resize Array Passed To Function As Param

I am trying to re-size an array passed as a parameter in a function. The problem is once I am done copying the array and I go to delete the old array the program fails.

I get this error which I have been unable to solve. Is what I am trying to do legal?

expression:_BLOCK_TYPE_IS_VALID

1
2
3
4
5
6
  void function(int oldArray[])
{
        create newArray and copy oldArray data into newArray  
	delete[] oldArray;
        oldArray = newArray;
}
oldArray in function is actually a pointer. There would be no difference if you wrote it like this:
1
2
3
4
5
6
void function(int* oldArray)
{
	create newArray and copy oldArray data into newArray  
	delete[] oldArray;
	oldArray = newArray;
}


oldArray is a local variable inside the function. Changes made to it will have any effect on the pointer that you passed to the function.

I recommend you use std::vector instead, if you want something that behaves like a resizable array.
Topic archived. No new replies allowed.