传智扫地僧课程学习笔记。
#include "iostream"
using namespace std;
template <typename T>
class A
{
public:
A( T a=0)
{
this->a = a;
}
void printA()
{
cout<<"a:"<<a<<endl;
}
protected:
T a;
};
class B: public A<int>
{
public:
B( int a = 10, int b = 20) : A<int>(a)
{
this->b = b;
}
void printB()
{
cout<<"a:"<<a<<" b:"<<b<<endl;
}
private:
int b;
};
void useA( A<int> &a)
{
a.printA();
}
void main()
{
B b1( 1, 2);
b1.printB();
system("pause");
}
还是注意A<int>,
1, class B :public A<int>
2, B( int a=10, int b=20):A<int>(a)