// 泛型编程.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
//类模板
template <class T>
class CC
{
public:
void hh(T itemp){}
void pp(T kk){}
};
//类模板的特化
template<>
class CC<std::string>{
public:
void hh(std::string pp){}
};
//类模板
template<typename t1, typename t2>
class BB
{
public:
BB()
{
cout << "BB cons" << endl;
}
};
//类模板的局部化
template <typename T>
class BB<T, T>
{
public:
BB()
{
cout << "local BB cons" << endl;
}
};
//类模板的缺省实参
template <class T, typename AINT = int>
class AA
{
public:
AA();
};
AA<class T, int>::AA()
{
};
int _tmain(int argc, _TCHAR* argv[])
{
BB<int, int> ibb;
getchar();
return 0;
}
类模板的特化,局部化以及缺省模板的实参
最新推荐文章于 2021-12-10 19:17:49 发布