11th Week Reading procedure (4)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.