| Chervil (1205) | |
|
@cPlusN00b That looks ok. It compiled and executed (though that's no guarantee of correctness). I personally prefer to match each use of new with a corresponding delete, and preferably at the same level in the hierarchy. Here it is left for main() to do the required delete [] p_returned;. Myself, if main is to do the delete, then I think main should also do the new. But if we do that, then there's no advantage over just declaring the array locally within main.new without a delete is a cause of memory leaks. Certainly if the function was called more than once it would be an issue. It's also just a good habit to remember to always match them, in the same way that we always match { } braces and so on. | |
|
Last edited on
|
|
| cPlusN00b (92) | |
|
great thanks cherv! I will not be so scared to use new from now on :3 | |
|
Last edited on
|
|