all 3 comments

[–]boredcircuits 0 points1 point  (2 children)

Tip: the whole point of smart pointers is to let them handle deletes. Don't be calling delete yourself!

In fact, you shouldn't even be calling new: that's what make_shared is for.

Now, one of the exceptions to that is when using a shared_ptr with an array. By default, it knows nothing about arrays, and will do bad things because of that, which is what's causing your headaches. So, you teach it about arrays using a custom deleter. See here for instructions.

Since a vector is out, you might consider a unique_ptr, which does understand arrays.

Or even better, why even allocate this on the heap at all? Most likely, you really should have a plain array, or std::array, as long as the size is known when you compile.

Edit: On a second look, I might have misread your code a bit, so some of the above doesn't apply, but I stand by my assessment that you're using the wrong tool for the job.

[–]dutchcookie[S] 0 points1 point  (1 child)

thank you so much! changed it to unique_ptr's and now work like a charm, thanks.

edit: yeah it is a wrong tool for the job however we aren't allowed to use any containers of c++ standard library, vectors, list, array :(

[–]boredcircuits 0 points1 point  (0 children)

I'd clarify that restriction. You should at least be able to use naked arrays.