#include <bits/stdc++.h> // 引入所有标准 C++ 库的头文件,不建议使用

using namespace std; // 使用标准命名空间

class father // 定义一个名为 father 的类 { public: virtual void car(); // 定义一个名为 car 的虚函数 };

void father::car() // 实现 father 类中的 car 函数 { cout << 'void father::car()' << endl; // 输出一句话 }

class son : public father // 定义一个名为 son 的类,继承自 father 类 { public: void car(); // 定义一个名为 car 的函数 };

void son::car() // 实现 son 类中的 car 函数 { cout << 'void son::car()' << endl; // 输出一句话 }

class daughter : public father // 定义一个名为 daughter 的类,继承自 father 类 { public: void car(); // 定义一个名为 car 的函数 };

void daughter::car() // 实现 daughter 类中的 car 函数 { cout << 'void daughter::car()' << endl; // 输出一句话 }

int main() // 程序入口函数 { father f; // 创建一个 father 类的对象 f.car(); // 调用 father 类的 car 函数 son s; // 创建一个 son 类的对象 s.car(); // 调用 son 类的 car 函数 daughter d; // 创建一个 daughter 类的对象 d.car(); // 调用 daughter 类的 car 函数

return 0; // 返回 0 表示程序正常结束

}


原文地址: https://www.cveoy.top/t/topic/nHdU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录