国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++實例---虛基類的構造函數和初始化

2019-11-08 03:11:23
字體:
來源:轉載
供稿:網友

運行環境:macOS shell 代碼:

#include <iostream>#include <iomanip>#include <string>using namespace std;class base{PRotected: int x;public: base(int x1) { x = x1; cout<<"constructing base, x = "<<x<<endl; }};class base1 : virtual public base{ int y;public: base1(int x1, int y1):base(x1) { y = y1; cout<<"constructing base1, y = "<<y<<endl; }};class base2 : virtual public base{ int z;public: base2(int x1, int z1):base(x1) { z = z1; cout<<"constructing base2, z = "<<z<<endl; }};class derived:public base1, public base2{ int xyz;public: derived(int x1, int y1, int z1, int xyz1):base(x1),base1(x1,y1),base2(x1,z1) { xyz = xyz1; cout<<"constructing derived, xyz = "<<xyz<<endl; }};int main (){ derived obj(1,2,3,4); return 0;}

運行結果: 這里寫圖片描述


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 忻州市| 泸定县| 湘潭市| 丰顺县| 称多县| 鞍山市| 文昌市| 青州市| 湘乡市| 宁陕县| 德清县| 宜都市| 卢氏县| 平泉县| 西盟| 黔南| 宿州市| 宜春市| 宣化县| 十堰市| 长汀县| 芜湖市| 永登县| 庆城县| 乐都县| 涿鹿县| 肇庆市| 焉耆| 张家口市| 慈溪市| 调兵山市| 宁晋县| 兴隆县| 杭锦旗| 清流县| 陵川县| 南投县| 银川市| 聊城市| 安仁县| 湘乡市|