zoukankan      html  css  js  c++  java
  • 基类与派生类中有同名函数

     1 #include <iostream>
     2 #include <string.h>
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 
     6 class Student
     7 {
     8     public:
     9         Student(int,string,float);
    10         void display();
    11     protected:
    12         int num;
    13         string name;
    14         float score;
    15 };
    16 
    17 Student::Student(int n,string nam,float s)
    18 {
    19     num=n;
    20     name=nam;
    21     score=s;
    22 }
    23 
    24 void Student::display()
    25 {
    26     cout<<"num:"<<num<<"
    name:"<<name<<"
    score:"<<score<<"
    
    ";
    27 }
    28 
    29 class Graduate:public Student
    30 {
    31     public:
    32         Graduate(int,string,float,float);
    33         void display();
    34     private:
    35         float pay;
    36 };
    37 
    38 void Graduate::display()
    39 {
    40     cout<<"num:"<<num<<"
    name:"<<name<<"
    score:"<<score<<"
    pay="<<pay<<endl;
    41 }
    42 
    43 Graduate::Graduate(int n,string nam,float s,float p):Student(n,nam,s),pay(p){
    44     
    45 }
    46 int main(int argc, char** argv) {
    47     Student stud1(1001,"li",88);
    48     Graduate grad1(2001,"wang",99,555);
    49     Student *pt=&stud1;
    50     pt->display();
    51     pt=&grad1;
    52     pt->display();
    53     return 0;
    54 }
  • 相关阅读:
    SQL获取当天0点0分0秒和23点59分59秒方法
    全球唯一标识符 System.Guid.NewGuid().ToString()
    Js获取当前日期时间及其它操作
    MySQL日期函数与日期转换格式化函数大全
    访问者模式
    享元模式
    中介者模式
    职责链模式
    命令模式
    桥接模式
  • 原文地址:https://www.cnblogs.com/borter/p/9405507.html
Copyright © 2011-2022 走看看