As Nemanja Boric pointed out in the comment, you're overwriting your stack, so anything can happen. On my PC, it happens to be bad_alloc
in GCC, and plain segfault in clang.
Look closely on this line:
currentNode = ¤tNode[currentNode->getFils().size() - 1];
currentNode
is pointer to Node
. At the beginning, it points to variable root
, allocated on stack.
In the first iteration, it changes to ¤tNode[1 -1]
which equals to currentNode
. So nothing happens (this isn't intended I suppose).
In the next iteration it changes to ¤tNode[2 - 1]
which equals to ¤tNode[1]
, which equals to currentNode+1
. That is an address on the stack, right after the root
variable. It's allocated, but it's value is not a Node*
! It can belong to int n;
, but it may be completely different, base on compiler optimizations.
In the 3. iteration, when you try to use this address as a Node
instance (which is not), you get undefined behavior and them literally anything can happen. It can kill your cat and burn your house. So you're still lucky, to get only bad_alloc
.