#include "stdafx.h"
#include <queue>
#include <iostream>
#include <map>
#include <string>
using namespace std;
// 类模板的使用
// 类模板中 类成员函数的申明与定义
// 结构体模板的使用
// 函数模板的使用
template <typename T> class A
{
public:
A();
A(T _a,T _b); // T 代表任何类型的数据
T sum();
private:
T a;
T b;
};
template <class T1,class T2>
struct Test
{
T1 H;
T2 W;
};
template <class T>A<T>::A() //类模板的成员函数是模板函数
{
a=0;
b=0;
}
template <class T>A<T>::A(T _a,T _b)
{
a=_a;
b=_b;
}
template <class T>T A<T>::sum()//注意观察成员函数的写法
{
return a + b;
}
template <class X>void swapFun(X &x,X &y) // X 代表任何数据类型
{
X tmp;
tmp=x;
x=y;
y=tmp;
}
int _tmain(int ar
类模板template的使用!
最新推荐文章于 2025-02-16 19:28:28 发布