设为首页 加入收藏

TOP

C++模板类复习
2015-11-21 01:03:33 来源: 作者: 【 】 浏览:1
Tags:模板 复习
//C++模板类复习
#include
using namespace std;


template
class test
{
private:
T1 temp1;
T2 temp2;
public:
test(){}
test(T1 data1, T2 data2):temp1(data1),temp2(data2){}
void show();
};


template //定义模板类成员
void test ::show()
{
cout << "原始类" << endl;
cout << temp1 << endl << temp2 << endl;
}


template <> //显示具体化
class test
{
private:
int temp1;
int temp2;
public:
test(){}
test(int one, int two):temp1(one), temp2(two){}
void show()
{
cout << "具体化" << endl;
cout << temp1 << endl << temp2 << endl;
}
};


template
class test
{
private:
T temp1;
double temp2;
public:
test(){}
test(T data1, double data2):temp1(data1), temp2(data2){}
void show()
{
cout << "部分具体化" << endl;
cout << temp1 << endl << temp2 << endl;
}
};


template class test ; //模板类的显示具体化和显示实例化不会冲突,因为显示具体化不会创建类声明


//将模板类作为内置成员
template
class test1
{
private:
template
class test2
{
private:
T2 data2;
public:
test2(){}
test2(T2 d):data2(d){}
void show2()
{
cout << data2 << endl;
}
};
test2 data1;
public:
test1(T1 d):data1(d){}
void show1()
{
data1.show2();
}
};


template
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++删除大量重复数字并且按升序排.. 下一篇Delete HDU5210 (模拟贪心)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: