Well, return ends the execution of a function, so of course any code after a return statement is not executed. And your function is of no use when you delete the allocated memory within the function.
What exactly are you trying to do? I don't think it is very useful to have a matrix object create and return another matrix object.
The solution to your problem is most likely to avoid pointers. Use objects instead of pointers wherever possible. Implement copy constructor and assignment operator for you class and never allocate objects manually.
Use it like
- Code: Select all
Matrix cc1(4, 5.5);
Matrix c = cc1.Resize(1); // if you really want this strange resize function
If you don't use new you don't have to care about the delete, it's that simple.
PS: The simple answer would be: The Resize method should return the pointer, so the memory address is not lost and you can delete it in the main function. But I really think you should take the long way and fix the structure of your code.
Who needs a signature anyway.