猴年生的女宝宝取名:c++ 模版介绍

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 21:46:26
C++模版如何写,

#include <cstdlib>
#include <iostream>

template <class T>
//在以后的引用中T为任意数据类型
T add(T x, T y)
{
return x+y;
}

using namespace std;

int main(int argc, char *argv[])
{
int a(2),b(3);
//int可改成其它的数据类型,只要支持"+"运算就OK了
cout<<add(a,b)<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}

//想弄得非常明白的话,最好自己去看书