回覆列表
  • 1 # 手機使用者86150361507

    舉個例子吧:

    class base1{

    int x;

    public:

    base1(int a){x = a;}

    };

    //單繼承

    class derived1: public base1{

    int a;

    public:

    derived1(int m, int n): base1(m){ //依次呼叫基類的建構函式,然後再是派生類的建構函式

    a = n;

    }

    };

    class base2{

    int t;

    public:

    base2(int p){t = p;}

    };

    //多繼承

    class derived2: public base1,public base2{

    int k;

    public:

    derived2(int x, int y, int z): base1(x),base2(y){ //依次呼叫基類建構函式,用逗號隔開,末尾沒有分號

    k = z;

    }

    };

  • 中秋節和大豐收的關聯?
  • 怎麼鑑定保溫杯有害物質?