cannot convert from Node<T>* to const int

Pages: 12
You have two functions with name find_node. One of them is a class member-function and is defined the following way

1
2
3
4
5
6
7
8
9
template <typename T >
inline void Node < T> :: find_node(  Node< T > *root, const T &val) const 
{
    const T & ptrFoundNode = find_node( val, root );
    if( ptrFoundNode ) 
	{
        delete_node( ptrFoundNode, root );
    }
}


The other is a non-class function and is defined the following way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
template <typename T>
const T * find_node(  Node<T> *root, const T &val) 
{
     const T * curr = root;
    while( curr != 0 )
    {
        if (val == curr -> _value)  {
           break;
        }
        else if (val < curr -> _value) {
            curr = curr -> _left;
        |
        else {
            curr = curr -> _right;
        }
    }
    return curr;
    }
}


As you see the class member-function returns nothing that is it has return type void. while the non-class function has return type const T *.
It seems that your intention is to call the non-class function from the member-function (see the statement
const T & ptrFoundNode = find_node( val, root );
in the member-function)

However the member-function hides the non-class function that is the compiler thinks that you are trying to call the member-function itself. But the member-function has different parameters compared with arguments you are passing to the call. So the compiler issues the error.

To escape the error you should place using directive in the member fiunction. For example



1
2
3
4
5
6
7
8
9
10
11
template <typename T >
inline void Node < T> :: find_node(  Node< T > *root, const T &val) const 
{
    using ::find_node;

    const T & ptrFoundNode = find_node( val, root );
    if( ptrFoundNode ) 
	{
        delete_node( ptrFoundNode, root );
    }
}

Last edited on
Topic archived. No new replies allowed.
Pages: 12