S
Steven T. Hatton
I had the most bizarre C++ experience yet. I was traversing a tree using a
visitor pattern which I had mistakenly given bad information about where to
go in the tree. I'm pretty sure it was climbing out of the bottom. That
doesn't surprize me. The fact that it caused the program to crash is to be
expected. But when I looked at the stack in the debugger, it was saying
that this=0x0, and then showing me the value of a member of the object that
had a null pointer for /this/.
What the way the program works is that I pass a visitor object to a member
function on the root node of the tree. Then nodes pass the visitor to one
of their child nodes until it reaches a leaf. When it gets to a leaf, the
traversal function behaves differently, in that it calls a method on the
visitor like this visitorObject->visit(this). I could trace it past the
call to visit(this). That tells me that the functions were invoked for a
non-existant object. Does anybody else find that strange?
visitor pattern which I had mistakenly given bad information about where to
go in the tree. I'm pretty sure it was climbing out of the bottom. That
doesn't surprize me. The fact that it caused the program to crash is to be
expected. But when I looked at the stack in the debugger, it was saying
that this=0x0, and then showing me the value of a member of the object that
had a null pointer for /this/.
What the way the program works is that I pass a visitor object to a member
function on the root node of the tree. Then nodes pass the visitor to one
of their child nodes until it reaches a leaf. When it gets to a leaf, the
traversal function behaves differently, in that it calls a method on the
visitor like this visitorObject->visit(this). I could trace it past the
call to visit(this). That tells me that the functions were invoked for a
non-existant object. Does anybody else find that strange?