Pointer deletion confusion

Hi All,

I have created a function which returns a matrix object of a class called Matrix by processing another matrix object. What it does is that it gets the passed matrix object, creates a new matrix object and points at it using a pointer, copies all the data from source matrix object to destination new matrix object, and returns the new matrix object.

Now I am confused here about which pointer to set as null and then delete. I am creating two matrix objects here, but the function is returning one. Do I need to delete the passed matrix object inside the function after it has been copied to the other new matrix object?

Thanks :)
You should delete all the values that aren't needed any more and keep the one returned by the function.
Now I am confused here about which pointer to set as null and then delete.
You should first delete and then set to zero ( NULL )
Thanks for clarifying!
Topic archived. No new replies allowed.