/* Find an item in an array-like object
* @param val the val to search for
* @param arr an array-like object in which to search for the given value
* @param size the size of the array-like object
* @return the index of the val in the array if successful, -1 otherwise
*/
template < class T>
int mybsearch(T val, T const arr[], const int &size)
当我尝试使用 const char* 和字符串数组调用此模板函数时,编译器会抱怨... mybsearch("peaches", svals, slen)
,我该如何修改模板原型以适应这种情况?
这是字符串数组
string svals[] = { "hello", "goodbye", "Apple", "pumpkin", "peaches" };
const int slen = sizeof(svals)/sizeof(string);