malloc 返回值的类型是 void *,所以在调用 malloc 时要显式地进行类型转换,将 void * 转换成所需要的指针类型。

 #include <iostream>

 using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//定义名为max_value的函数模板
template <class T> T max_value (T a,T b)
{
return ((a> b)? a: b);
} //在main()函数中测试max_value函数模板 int main(int argc, char** argv) {
//double类型数据使用max_value模板函数
double x = 1.2, y = 2.1;
cout<<"x="<<x<<"\t";
cout<<"y="<<y<<endl;
double result=max_value(x,y);
cout<<"max_value(x,y)="<<result<<endl;
cout<<"max_value(2*3.0,2+3.0)="<<max_value(*3.0,+3.0)<<endl;
cout<<"------------------"<<endl; //int类型数据使用max_value模板函数
int n= , m= ;
cout<<"n="<<n<<"\t";
cout<<"m="<<m<<endl;
cout<<"max_value(n,m)="<<max_value(n,m)<<endl;
cout<<"------------------"<<endl; //char类型数据使用max_value模板函数
char ch1='A',ch2='a';
cout<<"ch1="<<ch1<<"\t";
cout<<"ch2="<<ch2<<endl;
cout<<"max_value(ch1,ch2)="<<max_value(ch1,ch2)<<endl;
cout<<"------------------"<<endl; //字符串数据使用max_value模板函数
char str1[]="abc",str2[]="ABC",*p;
p=max_value(str1,str2);
cout<<"max_value("<<str1<<","<<str2<<")="<<p<<endl;
return ;
}

最新文章

  1. nginx File not found
  2. 通过jxl 读取excel 文件中的日期,并计算时间间隔
  3. uva oj 567 - Risk(Floyd算法)
  4. 【processing】小代码
  5. jenkins+gerrit
  6. Redis监控方案
  7. Markdown语法备忘
  8. Android 更好的Activity生命周期回调
  9. CustomSummaryCalculate 用法
  10. SpringMVC框架(一)
  11. 一位有着工匠精神的博主写的关于IEnumerable接口的详细解析
  12. 机器学习中的K-means算法的python实现
  13. 物料REVISION控制
  14. [Error]Can&#39;t install RMagick 2.13.4. You must have ImageMagick 6.4.9 or later.
  15. luogu P2617 Dynamic Rankings &amp;&amp; bzoj 1901 (带修改区间第k大)
  16. 【mysql】 mysql忘记密码
  17. php 图形用户界面GUI 开发
  18. paired-end reads的拼接
  19. vscode下调试caffe源码
  20. Android Fragment(三)ListFragment简单介绍以及Fragment之间通信

热门文章

  1. 完整的JavaScript版的信用卡校验代码
  2. Ubuntu14.04怎样使用root登录
  3. Zmodem transfer canceled by remote side问题的解决办法!
  4. 虚析构函数? vptr? 指针偏移?多态数组? delete 基类指针 内存泄漏?崩溃?
  5. OCR 识别原理
  6. nginx Beginner’s Guide
  7. unity, 不要change Default sharedMaterial
  8. Spring Cloud(七):使用SVN存储分布式配置中心文件和实现refresh
  9. Python目录常用操作
  10. atitit.Atitit. Gui控件and面板-----服务端控件 java struts的实现最佳实践