用存在的类构造出新的类比如说学生从人继承的关系如下
被继承的类:基类,超类,父类
来继承的类:派生类,子类
表示X继承A类
class X : public A()
{
}
class A
{
public:
A() : i(0)
{
cout << "A:A()" << endl;
}
~A()
{
cout << "A:~A()" << endl;
}
void print()
{
cout << "A::f()" << i << endl;
}
void set(int ii)
{
i = ii;
}
private:
int i;
};
class B : public A
{
public:
void f()
{
set(20);
print();
}
};