So im in a collage c++ class, and i missed my last class, so my teacher told me to try lab 5, i think i have templates down but im getting a compiler error saying that my function is ambigious..
the exact error is
Error 1 error C2782: 'T searchArray(T,T,int)' : template parameter 'T' is ambiguous
c:\documents and settings\psdao01\my documents\visual studio 2008\projects\lab5\lab5\driver.cpp 44 Lab5
#include<iostream>
#include<string>
using namespace std;
template <class T>
T searchArray(T index, T answer, int numOfParts){
int rIndex=-1;
for(int i=0,i<numOfParts,i++){
if index[i]=answer;
rIndex=i;
}
return rIndex;
};
int main(){
const int numOfParts = 7;
string items[numOfParts];
//create numOfParts items
/***** the below initializes the structure with part numbers
and names ****/
int items2[numOfParts];
items[0] = "AA";
items2[0]= 6;
items[1] = "BB";
items2[1]= 5;
items[2] = "CC";
items2[2]= 4;
items[3] = "DD";
items2[3]= 3;
items[4] = "EE";
items2[4]= 2;
items[5] = "FF";
items2[5]= 1;
items[6] = "GG";
items2[6]= 0;
string strEnd;
string itemA = "GG";
int itemB = 5;
cout <<"The first item was found at:";
cout << searchArray(items,itemA,numOfParts)<<endl;
cout <<"The second item was found at:";
cout << searchArray(items2,itemB,numOfParts)<<endl;
cout <<"Thank you" <<endl;
cin.get();
return 0; //return the value 0 to the OS
}