#include <iostream>
using namespace std;
template<typename T>
class A
{
public:
A(T t):a(t){}
void printA()
{
cout<<"a: "<<a<<endl;;
}
private:
T a;
};
//模板类派生普通类,子类从模板类继承的时候,需要让编译器知道父类的数据类型具体是什么(数据类型的本质:固定大小内存快的别名)
class B: public A<int>
{
public:
B(int t1, int t2):A(t1), b(t2){}
void printB()
{
A::printA();
cout<<"b: "<<b<<endl;
}
private:
int b;
};
//模板类派生模板类
template<typename T>
class C: public A<T>
{
public:
C(T t1, T t2):A(t1),c(t2){}
void printC()
{
A::printA();
cout<<"c: "<<c<<endl;
}
private:
T c;
};
int main()
{
B b(1, 2);
b.printB();
C<int> c(3, 4);
c.printC();
return 0;
}