C++ 虚函数,纯虚函数的作用和使用方法

您所在的位置:网站首页 纯虚函数怎么声明出来的 C++ 虚函数,纯虚函数的作用和使用方法

C++ 虚函数,纯虚函数的作用和使用方法

2024-07-01 08:53| 来源: 网络整理| 查看: 265

基类与派生类中有同名函数。在下面的程序中Student是基类,Graduate是派生类,它们都有display这个同名的函数。

#include #include using namespace std; //声明基类Student class Student { public: Student(int, string,float); //声明构造函数 void display( );//声明输出函数 protected: //受保护成员,派生类可以访问 int num; string name; float score; }; //Student类成员函数的实现 Student::Student(int n, string nam,float s) { //定义构造函数 num=n; name=nam; score=s; } void Student::display( ) { //定义输出函数 cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3