#include <iostream>
#include <string>
//注意头文件:string 和 string.h 的区别;
using namespace std;
//类模板碰到继承的问题以及解决:
template <class T>
class Base
{
public:
T m_A;
};
//需要告诉编译器,在继承Base类时,就要指定类型;
//否则T无法分配内存;
//必须让子类告诉编译器父类中的类型;
class Child :public Base<int>
{
};
template<class T1,class T2>
class Child2 :public Base<int>
{
public:
Child2()
{
cout << typeid(T1).name() << endl;
cout << typeid(T2).name() << endl;
}
T1 m_B;
};
void test01()
{
Child2<int, double>child;//由用户指定类型。T1 m_B的类型为int,T2 m_A的类型为double;
}
//输出int 和 double;
int main()
{
test01();
return 0;
}
继承