/* 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)
,我怎麼能修改模板原型,以適應這一點?爲const char *作爲參數傳遞給模板
這裏是字符串數組
string svals[] = { "hello", "goodbye", "Apple", "pumpkin", "peaches" };
const int slen = sizeof(svals)/sizeof(string);
編譯器抱怨什麼?請發佈錯誤消息。 –
'svals'的類型是什麼? –
而錯誤信息是...? – jpalecek