My linked list contains getters and setters. But once the program reaches the try exception handler to pop the values from the stack. I receive the following violation: -
Exception thrown: read access violation.
**this** was nullptr. occurred.
Okay Pop() is throwing an exception, what does that tell you?
Did you try running the program with your debugger? The debugger will be able to tell you exactly where the problem occurs and allow you to view the variables at the time of the exception.
note: I cannot make any changes to the classes or add arrays/variables.
Well if you can't make any changes to the classes, what are you allowed to do, especially since the problem is in one of the class functions that you say you can't modify?
Also I suggest you see about increasing your compiler warning levels and fix all warnings that should be issued by your compiler, such as:
In member function ‘int Stack::Pop()’:|
warning: declaration of ‘tmp’ shadows a previous local [-Wshadow]|
Hello, I didn't actually run your code, but you seem to be re-assigning top to top->getNext() in both NodePop() and in Pop(). Is this intentional? If I'm correct, this makes top become top->getNext()->getNext(). And if you only have 1 element, this will fail.
If I'm correct, you need to decide which place you want to actually modify the data structure; in NodePop() or Pop()? Your naming convention is a bit ambiguous... maybe you should change Pop()'s name to Top() [returns the top-most node without popping], and then change NodePop()'s name to just Pop().