编写一函数add()能对基本类型(short,char,int,long,float...)的数据进行加运算,返回和;对 bool型数据进行"或"运算;对字符串进行
主要考察C++中的函数重载和函数模板
/**************************************************************************************** *
* 编写一函数add()能对基本类型(short,char,int,long,float...)的数据进行加运算,返回和;对*
* bool型数据进行"或"运算;对字符串进行“加和”。
******************************************************************************************/
#include<iostream>
using namespace std;
#include<Cstring>
template<class T1,class T2>//函数模板的定义
T1 add(T1 x,T2 y)
{
return x+y;
}
bool add(bool x,bool y){
return x|y;
}
char *add(char *x,char *y){
strcat(x,y);
return x;
}
int main()
{
short sh1=1,sh2=2;
char c1='1',c2='2';
int i1=100,i2=200;
long l1=100000,l2=200000;
float f1=3.1,f2=100.2;
bool b1&#