Template

Is this correct? On line 4, should I use "int" instead of "T"?

#include <iostream>
using namespace std;

template <class T>
T Search(int Left, int Right, T X[], T E){
if (Left>Right) return -1;
int Middle=(Left +Right)/2;
if (X[Middle]==E) return Middle;
if (X[Middle]>E) return Search (Left, Middle-1, X, E);
if (X[Middle]<E) return Search (Middle+1, Right, X, E);
}

void main(){
int A[]={0, 1, 9, 11, 31, 72, 100, 101};
cout<<Search(0, 7, A, 72);

double B[]={0, 1, 9, 11.213, 31.1231, 72.2, 100.33,101.234};
cout<<Search (0, 7, B, 11.213);
}
You want to return int, not T.
Thank you
Topic archived. No new replies allowed.