Questions and codes:
/* *copyright (c) 2016, Yantai University School of computer *all rights reserved. * File name: Zwj.cpp * Author: Zhang Weijing * Completion date: May 10, 2016 * Version number: v1.0 * * Problem Description: Read the program, write the results of the operation * Input Description: * Program output: */#include <iostream>using n Amespace Std;class base{public:base (char i) {cout<< "Base constructor.--" <<i<<endl;}}; Class Derived1:virtual public base{public:derived1 (Char I,char j): Base (i) {cout<< "Derived1 constructor.--" <& lt;j<<endl;}}; Class Derived2:virtual public Base{public:derived2 (Char I,char j): Base (i) {cout<< "Derived2 constructor.--" <& lt;j<<endl;}}; Class Myderived:public Derived1,public derived2{public:myderived (char i,char j,char k,char l,char m,char N,char x): Derived2 (I,j), Derived1 (k,l), Base (M), d (n) {cout<< "myderived constructor.--" <<x<<endl; }private:base D;}; int main () {myderived obj (' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G '); return 0;}
Operation Result:
Process Analysis:
Virtual inheritance, call order, ①base and call only once. Output base constructor.--e. ②derived1, Output Derived1 constructor.--d. ③derived2, Output Derived2 constructor.--b. ④base d, Output Base constructor.--f. ⑤ output myderived constructor.--g.
11th Week Reading procedure (4)