No matching function for template function

I am trying to make a template function to calculate the median of a vector, but this:
1
2
3
4
5
6
7
8
9
template <class RandIt, class T>
T median(RandIt beg, RandIt end)
{
    sort(beg, end);

    RandIt mid = beg + (end - beg) / 2;

    return (end - beg) % 2 == 0 ? (*mid + mid[-1]) / 2 : *mid;
}

doesn't work and the compiler says there is no matching function when I call it by median(numbers.begin(), numbers.end()) with number being a vector<double>.

however, when I took out the T and replaced it with double:
1
2
3
4
5
6
7
8
9
template <class RandIt>
double median(RandIt beg, RandIt end)
{
    sort(beg, end);

    RandIt mid = beg + (end - beg) / 2;

    return (end - beg) % 2 == 0 ? (*mid + mid[-1]) / 2 : *mid;
}

it worked...

So what was wrong with the top function? Thank you!
Topic archived. No new replies allowed.