1.类模版及它的全具体化,半具体化
template
/类模板全具体化
template<>
class Test
{
public:
int m_a;
string m_b;
Test(int a, string b):m_a(a),m_b(b)
{
qDebug()<< "m_a"<
//类模板半具体化
template
class Test
{
public:
T m_a;
string m_b;
Test(T a, string b):m_a(a),m_b(b)
{
qDebug()<<"m_a"<
2.模板之间的继承(3种)关系 。(照顾好基类的构造函数)
2.1模版类继承普通类
//普通类
class AA
{
public:
int m_a;
string m b;
AA(int a,string b):m_a(a),m_b(b)
{
qDebug()<<"m_a"<m_a;
}
}
//类模板继承普通类
template
class Test:public AA
{
public:
T1 m_a;
T1 m_b;
Test(Tl a,Tl b,int c,string d):m_a(a),m_b(b),AA(c,d)
{
qDebug()<< "m_a"<
怎么使用
int main(int argc, char *argv[])
Test ts(7,9,3,"birdsB");
2.2普通类继承模版类
//先写模版类
templateclass BB{
public:
})
Tl m_a;T2 m b;
BB(T1 a,T2 b):m_a(a),m_b(b){qDebug()<<"m_a"<m_a;}
//写普通类继承模版类
templateclass AA:public BB{
public:
int m a;
string m b;
AA(int a,string b,Tl c,T2 d):m_a(a),m_b(b),BB(c,d)
{
qDebug()<<"m_a"<m_a;
}
使用方法
int main(int argc, char *argv[])
{
AA a(4,"he",5,"dgf");
}
2.3类模板继承类模板
//模版类:BB
templateclass BB
{
public:
Tl m_a;
T2 m b;
BB(T1 a,T2 b):m_a(a),m_b(b)
{
qDebug()<<"m_a"<m_a
}
}
模版类CC继承BB
template
{
public:
T1 m_a;
T2 m_b;
CC(T1 a,T2 b,T3 c,T4 d):m_a(a),m_b(b),BB(c,d)
{
qDebug()<<"m_a"<m_a;
}
void show();
怎么使用
int main(int argc, char *argv[])
{
CC a(4,"he",5.0,"dgf");
}
模版类继承模版类,成员变量类外实现
template::show()
{
}