#Memory Allocation Issue

36 messages · Page 1 of 1 (latest)

tall craneBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

sweet blaze
#

Code please

tight fox
tough whale
#

The problem is that you are declaring MOVIE_SIZE_LIST to be 32, but only have 8 movies defined, so in MovieTicketMaster::Init(), you are trying to access movie_name_list[8], which fails since there are only 8 strings in the array

#

Also, you're directly dereferencing a null pointer on line 240, though that is after the error above, so you haven't run into that yet

tough whale
#

The problem is that you're looping with the assumption of having enough movies, you should only be looping up to kSize, and setting the rest to empty strings/0 instead of trying to access

tough whale
#

Weird, for me that's line 238-240

tight fox
#

is that not me setting it as a nullptr?

tough whale
#

Yes, but look at the last line, without modifying p_movie, you're accessing it; or trying to at least

tight fox
#

so should add && p_movie != nullptr

#

but as the first condition

#

so p_movie != nullptr && p_movie->get_movie_name() == movie

tough whale
#

Then you still get a similar error, since nullptr++ is likely not where the first movie is located, it should be something like p_movie = movie_list, to get the first movie in the list, and loop from there

tight fox
#

what if i chnaged it to

Movie* p_movie = movie_list[0];
for(int i = 0; i < MOVIE_LIST_SIZE; i++){
if(p_movie->get_movie_name() == movie)

tight fox
tough whale
#

Also, I think it might be better for you to go through the debugging yourself, and try to understand what is going wrong: https://onlinegdb.com/I576rG4lF (An online debugger, not the greatest, but sharable) - That way you can directly interact with your code, and see how it works behind the scenes

tight fox
#

sorry if im asking dumb questions im p new

tough whale
#

Or at least that is how it was for me

tough whale
tight fox
#

sorry i meant & movie_list[0]

tough whale
tight fox
tough whale
#

Or possibly to see how you solve the issue

tall craneBOT
#

@tight fox Has your question been resolved? If so, type !solved :)

tight fox
#

!solved

tall craneBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity