Is there an obvious reason this loops endlessly?
<p>I am writing an AST and Node class.</p>

<p>Basically, the AST has a vector of Nodes, 'Nodes'. Each Node item in this vector can have its owns children inside a vector of Node called, 'Children', each child is imply another Node object which can have its own children, too, etc..</p>

<p>I am writing a simply printable version of the AST, reading all nodes and printing them with respective padding (spaces, or whatever other string or character), for instance:</p>

<pre><code>NODE_EXPR
         NODE_INT_LIT
         NODE_OPERATOR_PLUS
         NODE_INT_LIT

NODE_IF_STMT
            NODE_EXPR
                     NODE_INT_LIT
                     NODE_OPERATOR_TRUTH_EQ
                     NODE_INT_LIT
            NODE_BODY
                     NODE_KYWD_RETURN
</code></pre>

<p>etc. Just a basic branching structure.</p>

<p>Now, the nodes just added to some AST using <code>ast.addNode(someNodeObjectByValue);</code>, will make it's parent (a pointer to a Node in the AST) equal <code>nullptr</code>, because it's parent is the AST itself. Whereas nodes added using the overloaded <code>ast.addNode(someNodeObjectByValue, pointerToParentNode);</code>will obviously make the provided node the newly added node's parent.</p>

<hr>

<h2>PROBLEM CODE</h2>

<p>The code below is the problem. It should set the temporary node reference being worked with to its parent once it's done, so that the next iteration can operate, and should eventually "break", when the current node object has no parent.</p>

<pre><code>string Node::getPadding(string padding) {
size_t len = 0;
Node* child = this;

    while (child-&gt;hasParent()) {
        len += child-&gt;Parent-&gt;getNodeNodeTypeString().length();
        child = child-&gt;Parent;
        //keeps looping :/
    }
    return StringManip::repeatString(padding, len);
}
</code></pre>

<p>I know this is something stupid,please ask for any code (it's quite a short *.cpp for the whole thing, but I didn't want to included unnecessarily.</p>

<p>EDIT: The whole (very short) */cpp</p>

<pre><code>//**C AST
void AST::addNode(Node node) {
    node._nodeID = NodeCount();
    node.Parent = nullptr;
    node.ParentAST = this;
    Nodes.push_back(node);
}
void AST::addNode(Node node, size_t parentNode) {
    node._nodeID = NodeCount();
    node.ParentAST = this;
    node.Parent = getNodeWithID(parentNode);
    node.Parent-&gt;Children.push_back(node);
}
Node* AST::getNodeWithID(size_t id) {
    for (size_t i = 0; i &lt; Nodes.size(); i++)
        if (Nodes[i].NodeID() == id) return &amp;Nodes[i];

}
void AST::popEndNode() {
    Nodes.pop_back();
}
void AST::deleteNode(size_t nodeID) {
    Nodes.erase(Nodes.begin() + nodeID);
}
size_t AST::NodeCount() {
    return Nodes.size();
}


//**C Node
string Node::getNodeNodeTypeString() {
    switch (NodeType) {
        ...
    case NodeType::TOKENTYPE_INT_LIT:
        return "TOKENTYPE_INT_LIT";
    break;
        ...
    default:
        return "UNKOWN_TOKEN_TYPE";
    }
}
bool Node::hasChildren() {
    return (Children.size() != 0);
}
size_t Node::childCount() {
    return Children.size();
}

string Node::getPadding(string padding) {
   //^^^
}
bool Node::hasParent() {
    return (Parent != nullptr);
}
size_t Node::NodeID() {
    return _nodeID;
}
</code></pre>