why did I get "ambigous" error when invoking same-named function in different namespace?

  argument-dependent-lookup, c++, gcc, syntax-error

I implement a function named make_heap() in namespace dsa. and I get error when I tried to invoke it and std::make_heap() to make comparison. GCC told me that:

call of overloaded ‘make_heap(dsa::Vector::iterator&, dsa::Vector::iterator&, std::greater)’ is ambiguous

The code is following, any suggestions?

template<typename _Random_It>
void make_heap(_Random_It first, _Random_It last)
{
    // get true value_type from the iterators
    using value_type = typename std::iterator_traits<_Random_It>::value_type;

    make_heap(first, last, std::greater<value_type>());   // << error here
}

template<typename _Random_It, typename _Comp>
void make_heap(_Random_It first, _Random_It last, _Comp compare)
{
    if(first + 2 >= last)
    {
        return ;
    }

    for(size_t i = (last - first) / 2; i > 0; i--)
    {
        __heapify(first, last, i, compare);
    }
}

Source: Windows Questions C++

LEAVE A COMMENT