/* 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);