it seems that all the int** map creates a memory leak, as they do not get deleted.. Would smart pointers help here.. or how?..
map should contain a 2d array which is initialized by set_map..
Well array has to be used here, as it required by the other functions..
but yeah.. I know that new is always followed by delete.. But how do I do it here..
I return the element.. but i can't delete before i return it.. The only possible solution i see is to use smart pointer, and let it get deleted as it goes out of scope... but how do i apply it here??
The only possible solution i see is to use smart pointer, and let it get deleted as it goes out of scope... but how do i apply it here??
If you use new it is up to you to use delete when that array is no longer necessary.
Using a smart pointer is the best idea, but it is not the only option. There are several other options, using one of the standard containers, encapsulating these pointers in a class of your own, etc.
And remember you'll probably also want to keep track of the sizes of these "arrays" as well.
Well array has to be used here, as it required by the other functions..
Why can't you change those other functions as well?
I still have to delete it, or remove somehow, before i return it?
What? You don't new a std::vector so why would you need to delete it? A std::vector will destruct it's self when it goes out of scope when properly used. Plus a vector knows it's size and can be easily passed to and from functions, you can even easily return a std::vector using the return statement.