If by "height of the tree" you mean how long are your "branches" you are not doing well. You have several problems of concept.

### Proposal.

Add to your class template `tree`

a function `altura`

that will consult all the nodes of its root how deep they are and will keep the maximum of them:

```
int tree::altura()
{
int a = 0;
for (auto &nodo : raiz)
a = std::max(a, deep(nodo, 0))
return a;
}
```

The above code assumes that your class `tree`

has a node named `raiz`

and that the node provides the functions `begin`

and `end`

.

The previous function calls the recursive function `deep`

that does almost the same as the function `altura`

with the difference that each level of recursion increases the level by 1, for this function the node must receive from the what to calculate and the depth from which to start counting:

```
int tree::deep(Nodo &n, int nivel)
{
int a = nivel;
for (auto &nodo : raiz_del_arbol)
a = std::max(a, deep(nodo, nivel + 1))
return a;
}
```

If the node we have reached has no children, its level will be the level provided in the call.

### Other things to consider.

You have some design flaws that I would like to comment on:

- Do not use free functions to do these operations, these functions force you to expose the data of your class, thus breaking the encapsulation.
- If you really have to use free functions, use a template function, or you'll be forced to create a version for each instantiation of the template
`tree`

.