国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}

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


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

圖片精選

主站蜘蛛池模板: 隆回县| 德令哈市| 榆树市| 龙口市| 黄冈市| 屯门区| 彭水| 商丘市| 图们市| 长顺县| 高州市| 施秉县| 柏乡县| 关岭| 蓬安县| 德昌县| 文成县| 新平| 井冈山市| 锡林浩特市| 大英县| 凤阳县| 黔南| 张家口市| 八宿县| 高尔夫| 灌云县| 张家界市| 固阳县| 龙岩市| 莱阳市| 抚州市| 当涂县| 沭阳县| 涡阳县| 宜宾县| 尖扎县| 洞头县| 东山县| 延津县| 湟源县|