zoukankan      html  css  js  c++  java
  • 基类的两个派生类再派生一个派生类 用virtual避免二义性

    class vehicle
    {
    int MaxSpeed;
    int Weight;
    public:
    vehicle(int maxspeed, int weight) :MaxSpeed(maxspeed), Weight(weight){}
    ~vehicle(){}
    int getMaxspeed()const { return MaxSpeed; }
    int getWeight()const { return Weight; }
    };
    class bicycle: virtual public vehicle
    {
    int Height;
    public:
    bicycle(int maxspeed, int weight, int height)
    :vehicle(maxspeed, weight), Height(height){}
    int getHeight()const { return Height; }
    };
    class motorcar :virtual public vehicle
    {
    int SeatNum;
    public:
    motorcar(int maxspeed, int weight, int seatnum) :vehicle(maxspeed, weight), SeatNum(seatnum){}
    int getseatnum()const{ return SeatNum; }
    };
    class motorcycle : public bicycle,public motorcar
    {
    public:
    motorcycle(int maxspeed, int weight, int height) :
    vehicle(maxspeed, weight), bicycle(maxspeed, weight, height),
    motorcar(maxspeed, weight, 1){}

    };

    int _tmain()
    {
    motorcycle a(80, 150, 100);
    cout << a.getMaxspeed() << endl;
    cout << a.getWeight() << endl;
    cout << a.getHeight() << endl;
    cout << a.getseatnum() << endl;

    }

  • 相关阅读:
    MySQL information_schema
    Sqlmap入门
    MySQL UNION
    Order by 1
    yum安装软件时,提示No package netstat available.的解决方法
    Centos7查看端口占用
    查看Centos版本
    Linux非交互方式设置密码
    Hive中的用户自定义函数
    Dbeaver连接Hive和Mysql的配置
  • 原文地址:https://www.cnblogs.com/huninglei/p/5470690.html
Copyright © 2011-2022 走看看