C++ Tree Class implementation I am trying to implement a class for the Node of a Tree in C++ in order to represent an HTML structure.
It is not complete by a shot, but i'd still like an opinion.

TreeNode.h :

#ifndef TreeNode_H
#define TreeNode_H

#include &lt;string&gt;
#include &lt;vector&gt;

class TreeNode
{
    private:
        std::string textContent;
        std::string tagName;

        TreeNode *parent;

        std::vector&lt;TreeNode *&gt; children;

        int countNodesRec(TreeNode *root, int&amp; count);

    public:
        TreeNode();
        TreeNode(std::string iTextContent, std::string iTagName);

        void appendChild(TreeNode *child);
        void setParent(TreeNode *parent);

        void popBackChild();
        void removeChild(int pos);

        bool hasChildren();
        bool hasParent();

        TreeNode* getParent();
        TreeNode* getChild(int pos);

        int childrenNumber();
        int grandChildrenNum();

        std::string getTextContent();
        std::string getTagName();
};

#endif


TreeNode.cpp :

#include "TreeNode.h"
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;


TreeNode::TreeNode() {};

TreeNode::TreeNode(std::string iTextContent, std::string iTagName) :
    textContent(iTextContent),
    tagName(iTagName),
    parent(NULL)
{}

int TreeNode::countNodesRec(TreeNode *root, int&amp; count)
{   
    TreeNode *parent = root;
    TreeNode *child = NULL;

    for(int it = 0; it &lt; parent-&gt;childrenNumber(); it++)
    {   
        child = parent-&gt;getChild(it);
        count++;
        //std::cout&lt;&lt;child-&gt;getTextContent()&lt;&lt;" Number : "&lt;&lt;count&lt;&lt;std::endl;
        if(child-&gt;childrenNumber() &gt; 0)
        {   
            countNodesRec(child, count);
        } 
    }

    return count;
}

void TreeNode::appendChild(TreeNode *child)
{       
    child-&gt;setParent(this);
    children.push_back(child);
}

void TreeNode::setParent(TreeNode *theParent)
{
    parent = theParent;
}

void TreeNode::popBackChild()
{
    children.pop_back();
}

void TreeNode::removeChild(int pos)
{   
    if(children.size() &gt; 0) {
        children.erase(children.begin()+ pos);
    }
    else {
        children.pop_back();
    }
}

bool TreeNode::hasChildren()
{
    if(children.size() &gt; 0)
        return true;
    else
        return false;
}

bool TreeNode::hasParent()
{
    if(parent != NULL)
        return true;
    else 
        return false;
}

TreeNode * TreeNode::getParent()
{
    return parent;
}

TreeNode* TreeNode::getChild(int pos)
{   
    if(children.size() &lt; pos)
        return NULL;
    else
        return children[pos];
}

int TreeNode::childrenNumber()
{
    return children.size();
}

int TreeNode::grandChildrenNum()
{   
    int t = 0;

    if(children.size() &lt; 1)
    {
        return 0;
    }

    countNodesRec(this, t);

    return t;
}

std::string TreeNode::getTextContent()
{
    return textContent;
}

std::string TreeNode::getTagName()
{
    return tagName;
}


Sample code :

#include &lt;iostream&gt;
#include &lt;vector&gt;
#include "TreeNode.h"

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {

    TreeNode *itr = NULL;

    TreeNode *node = new TreeNode("k", "p");
    node-&gt;appendChild(new TreeNode("test1", "testag"));
    node-&gt;appendChild(new TreeNode("test2", "testag"));
    node-&gt;appendChild(new TreeNode("test3", "testag"));

    itr = node-&gt;getChild(0);

    itr-&gt;appendChild(new TreeNode("test1a", "testtag"));
    itr-&gt;appendChild(new TreeNode("test1b", "testtag"));
    itr-&gt;getChild(0)-&gt;appendChild(new TreeNode("test1aa", "testtag"));

    itr = node-&gt;getChild(1);
    itr-&gt;appendChild(new TreeNode("test2a", "testtag"));
    itr-&gt;appendChild(new TreeNode("test2b", "testtag"));

    itr-&gt;getChild(0)-&gt;appendChild(new TreeNode("test2aa", "testtag"));

    std::cout&lt;&lt;node-&gt;grandChildrenNum();

    return 0;
}
Some quick comments:

Const correctness

You really should make your code const correct. 

For example at least these functions could be const declared:

    bool hasChildren();
    bool hasParent();

    TreeNode* getParent();
    TreeNode* getChild(int pos);

    int childrenNumber();
    int grandChildrenNum();

    std::string getTextContent();
    std::string getTagName();


Use references to avoid copies

This:

TreeNode(std::string iTextContent, std::string iTagName);


should be:

TreeNode(const std::string&amp; iTextContent, const std::string&amp; iTagName);


otherwise you are creating temporary copies of the strings when you pass them in.

These functions should return by const reference:

    std::string getTextContent();
    std::string getTagName();


Like so:

    const std::string&amp; getTextContent() const;
    const std::string&amp; getTagName() const;


Otherwise you will be creating unnecessary memory copies each time the function is called even if you just want to look at the value.

Memory leak galore?

Your API requires that you pass in raw pointers and store them in the node. There is no documentation of the ownership of the pointers. Who is responsible for freeing them? Right now all I see is a memory leak waiting to happen. 

In your main code you allocate the nodes with new but C++ is NOT a garbage collected language. You will need to pair each new with a delete to free the memory otherwise you will run out of memory faster than you can say "Holy memory management batman!".

Now, this keeping track of new/delete gets error prone very quickly so since C++11 you are recommended to use smart pointers. A.k.a. std::unique_ptr and std::shared_ptr for just about everything. See also std::make_unique and std::make_shared. There are places where you could/should use pointers, but as I gather that you are new to C++ I will not go into those detail because you can get away with just using smart pointers everywhere for now.

Also you might be interested in reading up on Resource Acquisition Is Initialisation (RAII). We ❤❤❤ RAII in C++.