1. 程式人生 > >模板類派生模板類

模板類派生模板類

#include<iostream>
using namespace std;
template <typename T>
class A
{
public:
	T a;
public:
	A(T a = 0)
	{
		this->a = a;
	}
	void printfA()
	{
		cout << "a= "<<a<< endl;
	}
};
template <typename T>
class B :public A < T >
{
public:
	B(T a = 0, T b = 0) :A<T>(a)
	{
		this->b = b;
	}
	void printfB()
	{
		cout <<"a="<< a<<"  b="<<b << endl;
	}
public:
	T b;
};
int main()
{
	A<int> a1;
	a1.printfA();

	B<int> b1;
	b1.printfB();
	system("pause");
	return 0;
}