类的继承
可以实现代码的复用 提高代码的使用率
// 基类(父类)
class Base {
public:
void baseFunction() {
cout << "Base function" << endl;
}
};
// 派生类(子类)
class Derived : public Base {
public:
void derivedFunction() {
cout << "Derived function" << endl;
}
// 可以覆盖基类的函数
void baseFunction() override {
cout << "Derived base function" << endl;
}
};