c++的函数调用二维数组指针

CSDN问答 2022-09-23 10:00:19 阅读数:318

c++函数数组调用二维
template<>auto max_n<char *>(char **char_arr, int num) -> char * { int max_str{}; char *max_point{}; for (int i = 0; i < num; ++i) { int temp_num{}; for (int j = 0; char_arr[i][j] != '\0'; ++j)++temp_num; if (temp_num > max_str)max_point = char_arr[i]; } return max_point;}auto sixth_practice() -> void { int int_num[9]{1, 6, 5, 7, 4, 2, 3, 9, 5}; cout << "int_num max number is " << max_n(int_num, 9) << endl;// char **str_arr = new char *[5]{new char[30]{}, new char[30]{}, new char[30]{}, new char[30]{}, new char[30]{}};// strcat(str_arr[0],"guanweiyv");// strcat(str_arr[1],"ankuo");// strcat(str_arr[2],"xvpeng");// strcat(str_arr[3],"wangyatao");// strcat(str_arr[4],"renhongchuan"); char str_arr[5][30] = {"guanweiyv", "ankuo", "xvpeng", "wangyatao", "renhongchuan"}; char *max_str = max_n(str_arr, 5);//这里报错No matching function for call to 'max_n' //但是我用上面注释的方法就可以完美运行,二维数组str_arr[0]不就是二维数组的指针吗, //二维数组的指针不就是指针的指针,这里为什么报错呢 cout << "max_str is "; for (int i = 0; max_str[i] != '\0'; ++i)cout << max_str[i]; cout << endl;}
版权声明:本文为[CSDN问答]所创,转载请带上原文链接,感谢。 https://ask.csdn.net/questions/7789484