• 第13章 类继承


    一个普通的类继承,包括构造函数传对象引用和参数列表初始化
    #ifndef TABLETENN1_H_
    #define TABLETENN1_H_ #include<string> using namespace std; class TableTennisPlayer { private: string firstname; string lastname; bool hasTable; public: TableTennisPlayer(const string &fn="none",const string &ln="none",bool ht=false); void Name()const; bool HasTable()const { return hasTable; } void ResetTable(bool v) { hasTable=v; } }; class RatedPlayer:public TableTennisPlayer { private: int rating; public: RatedPlayer(int r=0,const string &fn="none",const string &ln="none",bool ht=false); RatedPlayer(int r,const TableTennisPlayer &tp); int Rating()const { return rating;} void ResetRating(int r) { rating=r;} }; #endif
    #include<iostream>
    #include"tabtenn1.h"
    using namespace std;
    TableTennisPlayer::TableTennisPlayer(const string &fn,const string &ln,bool ht)
    {
        firstname=fn;
        lastname=ln;
        hasTable=ht;
    }
    void TableTennisPlayer::Name()const
    {
        cout<<lastname<<", "<<firstname;
    }
    RatedPlayer::RatedPlayer(int r,const string &fn,const string &ln,bool ht)
    {
        TableTennisPlayer(fn,ln,ht);
        rating=r;
    }
    RatedPlayer::RatedPlayer(int r, const TableTennisPlayer &tp):TableTennisPlayer(tp)
    {
        rating=r;
    }
    #include<iostream>
    #include"tabtenn1.h"
    using namespace std;
    int main()
    {
        TableTennisPlayer player1("Tara","Boomdea",false);
        RatedPlayer rplayer1(1140,"Maloory","Duck",true);
        rplayer1.Name();
        if(rplayer1.HasTable())
            cout<<" has a table!"<<endl;
        else
            cout<<" hasn't a table!"<<endl;
        player1.Name();
        if(player1.HasTable())
            cout<<" has a table!"<<endl;
        else
            cout<<" hasn't a table!"<<endl;
        cout<<"Name:";
        rplayer1.Name();
        cout<<";Rating: "<<rplayer1.Rating();
    
        RatedPlayer rplayer2(1212,player1);
        cout<<"Name: ";
        rplayer2.Name();
        cout<<";Rating: "<<rplayer2.Rating()<<endl;
    
        return 0;
    }
  • 相关阅读:
    APP测试中 iOS 和 Android有哪些区别呢
    软件测试的标准工作流程
    selenium在元素定位的时候,明明定位到元素却始终不可见
    接口测试要点
    测试用例的组成部分
    APP测试的全面性
    安卓出现ARN的原因
    测试的多个方面
    α测试和β测试
    接口自动化测试用例设计方法
  • 原文地址:https://www.cnblogs.com/yanlixin1993/p/4899820.html
Copyright © 2020-2023  润新知