First of all, I think that you may be confusing the depth of a tree with the height of a tree. Refer to What is the difference between tree depth and height? for an explanation.
For example, following are the depth and height of the nodes in this (binary) tree ('0' being the root):
0 -- depth 0, height 2
/ \
1 2 -- depth 1, height 1 and 2, respectively, for nodes 1 and 2
/ \
3 4 -- depth 2, height 0
As you can see, that the depth of the tree root is '0', which is O(1) computation. The height of the tree, however, is more interesting with regards to recursion and can be computed using the following:
struct TreeNode {
T _value;
typedef TreeNode* node_ptr;
node_ptr _left, _right;
};
...
int treeHeight(Node* node)
{
return std::max(node->_left? 1 + height(node->_left) : 0,
node->_right? 1 + height(node->_right) : 0);
}
...
std::cout << treeHeight(root);
...
The fundamental idea is this:
During the recursive (depth-first) traversal, if a leaf node is reached, return a value of '0' (which is the height of every leaf node). Otherwise, compute the height of the tree rooted at the non-leaf node (which is the max of the heights of the left subtree and the right subtree of that node + 1 for the node itself). Start from the root of the tree.
The second aspect that I want to address in your question is regarding what I gather from your function signature:
int treeDepth(int depth) const
and the way you are calling it:
root->treeDepth(1);
The depth of a tree is not conducive to being a property of the root. Instead, it is a property of the tree, which is composed of tree nodes, one of which is the root node. So, I would define the class (C++ struct shown here) as follows:
template<class T>
struct BinaryTree {
struct TreeNode {
T _value;
typedef TreeNode* node_ptr;
node_ptr _left, _right;
};
TreeNode _root_node;
typedef typename TreeNode::node_ptr node_ptr;
node_ptr _root;
...
int height(node_ptr node) const;
...
};
Finally, finding the depth of a given node in a tree:
int depth(node_ptr node) const;
// returns depth of node if it is in the tree, else -1
is a problem where you may apply recursion. However, a recursive approach is not natural and a breadth-first (or level-order) traversal will be more suited for this.