   Filter Box HELP (POINTERS)
  Hi there, im having trouble applying my filter box, my code for it follows:PS:I didnt write the code, i just modified the function, but it doesnt want to work anymore![Source]void BoxFilterHeightMap(int Length,float *HeightMap){  // Validate requirements  if (!HeightMap)   return; // Is the Pointer NULL  // Allocate the result  float *result = new float[Length];    // Make sure memory was allocated  if (!result)return;.. Do some stuff    // Release the old array  delete [] HeightMap;   // Store the new one  HeightMap = result;};-------------------OKAY I THINK I KNOW WHAT THE PROBLE IS, in my decleration i ask for a float *HeightMap, now this Points to the data (it is the address or location of that data).What i really want is the pointer, so that i can change its value and delete the data it is pointing to.Im just not sure how 2 do this!   
  The instruction HeightMap = result; assigns the value of result to HeightMap. Then, the variable heightmap is destroyed because it is an auto variable (just like any non-reference function argument), and your modification is lost. If you want to change the value of the variable that was passed to the function (instead of a copy of it), you need to pass that variable by reference (google 'C++ pass by reference').However, since you executed delete [] HeightMap, the object initially pointed to by HeightMap is destroyed. If anyone else tries to use that object, you will get an access violation. This would happen, for instance, in the code:void BoxFilterHeightMap(true,18,18,myHeightMap);myHeightMap[0] = 20; // access violation.Run your code through a debugger first, you will notice that it does not do what you think it does. At all. And don't forget that new[] → delete[], not delete.   ;  what do you meandon't forget that new[] → delete[], not delete.I use delete [] to delete all my memory allocated by new.. is this correct?--------------------------------------Well thanks that did the trick, if any1 wants 2 know below is the new code[Source]void BoxFilterHeightMap(bool smoothEdges,int Width,int Height,float *&H){  long Length = Width*Height;  float *HeightMap = H;    // Validate requirements  if (!HeightMap)    return;    // Allocate the result  float *result = new float[Length];    // Make sure memory was allocated  if (!result)    return;   // Release the old array  delete [] HeightMap;   // Store the new one  H = result;};[\Source];  Oops, my bad. Scratch the second part of the message, then. The first part (pass by reference) still holds.   