I am working on a project. The program is supposed display items from a vending machine. The user is supposed to be able to type in an item, pay an amount; then the vending machine gives the user their item. Well, the problem I am having is when I run the program it goes through the the whole process perfectly. Except when it prompts the user if they want to quit (either yes or no), windows promptly says the program has stopped working a must be closed. When debugging, I step through all of VendingMaching::run() and receive an access violation after receiving the user input and trys to execute this->display(); again at the beginning of the loop.
I have spent a considerable amount of time trying to figure this out by debugging and adjusting different things within the program, but I cannot find an adequate solution or any solution for that matter.
Any help and push in the right direction will be greatly appreciated. Thanks!
Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
It sounds like you have memory corruption - generally when memory is corrupted, either it is detected immediately, or it stays hidden until later in the program where it comes back into play. It is likely you are unlucky and it is not being detected immediately. Re-check all code that indexes into vectors/arrays and/or deal with pointers and make sure nothing is going out of bounds.
I just cannot seem to figure it out because everything works fine until the loop is either attempted to be exited (quit == "yes") or when it attempts to go back through for another iteration of the loop. It uses various virtual functions and inheritance, but I don't see any issues with those. I will adjust post to include destructor in case any abnormalities can be seen from that.. I have checked it numerous times and can't see any.
the purpose for that is to loop through the entire array and free the memory associated with each element. Then delete the entire array and etc. I figured that was the correct way to do it. But now that you say that that is likely the issue. Any idea on a correct way to do that or a point in the right direction? thank you for pointing that out.
Thank you for the tip. However, I am still getting an unhandled exception (0xC0000005: Access violation reading location 0x00000000.) It is still occurring in the same portion of the program and when trying to debug if I step into the display function on second call. I look to see what values are set to what and i noticed that _vfptr says it is unable to read memory...