Achiber

代码改变世界,让我们一起默默的努力!
随笔 - 4, 文章 - 2, 评论 - 0, 引用 - 0
数据加载中……

模板函数

#include <iostream>
#include 
<cstdio>
using namespace std;

template 
<typename T1 , typename T2>
T2 fun(T1 x,T2 y)
{
     T2 tmp 
= x *+ y * y + x * y;
     
return tmp;
}

int main(){
     
int x1 = 1, y1 = 4;
     
float x2 = 1.1 , y2 = 2.2;
     
double x3 = 2.0 , y3 = 3.1;
     cout 
<< fun(x1, y1) << endl;
     cout 
<< fun(x2, y2) << endl;
     cout 
<< fun(x3, y3) << endl;
     cout 
<< fun(x1, y2) << endl;
     
return 0;
}

posted on 2012-11-23 22:17 王文豪 阅读(202) 评论(0)  编辑 收藏 引用 所属分类: C++learning


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理