C++ primer plus 8.8_6

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
template <typename T>
T max5(T num[], int n);

template <> char* max5( char* ch[], int  n);

int  main(void)
{
	
	double num1[4]={1.2,2.4,3.6,4.8};
	int num2[6]={3,5,6,8,9,9};
	int r1=max5(num2,6);
	double r2=max5(num1,4);
	cout<<"r1 = "<<r1<<endl;
	cout<<"r2 = "<<r2<<endl;
    char *str[5]={"abc","abcde","abcdef","abcdefg","abcdefgh"};
	char*  r3=new char [20];
	r3 =max5(str,5);
	cout<<"r3  = "<<r3<<endl`;
	
	return 0;
}

template <typename T>
T max5(T num[], int n)
{
	int i;
	T max=num[0];
	for(i=1;i<n;i++)
	{
		if(max<num[i])
			max=num[i];
	}
	return max;
}
template <>char *max5( char *ch[], int n)
{
	int i;
	int max=strlen((ch[0]));
	
	int p=0;
	for(i=1;i<n;i++)
	{
		if(max<strlen((ch[i])))
		{
			p=i;
		}
	}
	return ch[p];
}

疑惑:19行警告 [Warning] deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

网上有人说要把具体化中的二维数组参数设为const,但改完之后又出现了别的错误,暂未解决。

上一篇:面试官问:Mybatis Plus 是如何实现动态 SQL 语句的?原理你懂吗?


下一篇:解决springboot启动userMapper类找不到错误