Your code is fine (at least, the part of your code you've shown us). The problem you're describing is simply that the Eclipse debugger crashes when you try to evaluate stack.top()
in it. This is a bug in Eclipse (specifically in its built-in support for inspecting C++ container types), and it's not something you can easily fix yourself.
One possible workaround would be to add debugging functions to your own code; for example
const Cell *stackTop(const std::stack<Cell> *stk)
{ return &stk->top(); }
Then whenever you want to get at stack.top()
in your debugging session, type in *stackTop(&stack)
instead. Notice that this definition of stackTop
avoids dealing with templates, inlining, references, and move-semantics — all of which are things with which I would expect the average debugger to have trouble — instead it's just a single non-templated function that takes a pointer and returns a pointer. It would take a very stupid debugger to get confused by this simple of a function.
If Eclipse can successfully inspect std::vector<Cell>
without crashing, then you might consider rewriting your code to use vector
instead of stack
; this will likely be more efficient anyway.