#include<iostream>
using namespace std;
template<typename T>
class A
{
public:
A(T a = 0)
{
this->a = a;
}
public:
void printA()
{
cout << "a:" << a << endl;
}
protected:
T a;
};
//子模板类派生时,需要具体化模板类,C++编译器需要知道 父类的数据类型具体是什么样子的
//要知道父类所占的内存大小是多少
class B :public A<int>
{
public:
B(int a = 20, int b = 20) :A<int>(a)
{
this->b = b;
}
void printB()
{
cout << "a:" << a << " b:" << b << endl;
}
protected:
int b;
};
//从模板类派生模板类
template <typename T>
class C :public A < T >
{
public:
C(T c, T a) :A<T>(a)
{
this->c = c;
}
void printC()
{
cout << "a:" << a << " c:" << c << endl;
}
protected:
T c;
};