泛型函数的一个有关问题…

泛型函数的一个问题……
/*使用模板函数(泛型函数)实现冒泡排序bubble_sort函数和二分查找binary_search函数。*/
#pragma warning(disable: 4786)
#include <iostream>
#include <vector>
#include <string>

using namespace std;

template<class T>
void bubble_sort(std::vector<T> & vec)
{
typedef typename vector<T>::size_type vec_sz;
vec_sz size = vec.size();
int i, j;
for (i = 0; i < vec.size(); i++){
for (j = 0; j < size - 1; j++){
if (vec[j] > vec[j + 1]){
T x = vec[j + 1];
vec[j + 1] = vec[j];
vec[j] = x;
}
}
}
}

template<class Ran, class X>
Ran binary_search(Ran begin, Ran end, const X &x)
{
Ran mid = (begin + end) / 2;
while (mid != x && begin < end){
if (x>mid){
begin = mid + 1;
}
else{
end = mid - 1;
}
mid = (begin + end) / 2;
}
if (mid == x){
cout << "Find it: " << x << endl;
}
else{
cout << "Can not find it: " << x << endl;
}
}
template<class T>
void read(std::vector<T> & vec){
T x;
while (cin >> x){
vec.push_back(x);
}
}

template<class In>
void print(In begin, In end){
while (begin != end){
cout << *begin << endl;
begin++;
}
}

int main(){
string flag;
cin >> flag;
if (flag == "string"){
string x;
cout << "please find: ";
cin >> x;
cout << x << endl;
std::vector<string> vec;
read(vec);
bubble_sort(vec);
print(vec.begin(), vec.end());
std::vector<string>::const_iterator it = binary_search(vec.begin(), vec.end(), x);
if (it != vec.end()){
cout << "Find it: " << *it << endl;
}
else{
cout << "Can not find it: " << x << endl;
}
}
else{
double x;
cout << "please find: ";
cin >> x;
cout << x << endl;
std::vector<double> vec;
read(vec);
bubble_sort(vec);
print(vec.begin(), vec.end());
std::vector<double>::const_iterator it = binary_search(vec.begin(), vec.end(), x);
if (it != vec.end()){
cout << "Find it: " << *it << endl;
}
else{
cout << "Can not find it: " << x << endl;
}
}
return 1;
}泛型函数的一个有关问题…
如图……请问该如何解决……初学者……不是很明白……
------解决思路----------------------
Ran和X之间怎么!=
Ran和int之间怎么+
没定义。
------解决思路----------------------
template<class Ran, class X>
Ran binary_search(Ran begin, Ran end, const X &x)
{
Ran mid =begin+(end-begin)/2;
while (*mid != x && begin < end){
if (x>*mid){
begin = mid + 1;
}
else{
end = mid - 1;
}
mid = begin+(end - begin) / 2;
}
if (*mid == x){
cout << "Find it: " << x << endl;
return mid;
}
else{
cout << "Can not find it: " << x << endl;
return end;
}
}

如上,你原来的binary_search有问题,改了下可以编译了!