Tenth week-Read the program

Source: Internet
Author: User

Read Program 4:

/*copyright  School of Computer and control engineering completion Date: May 6, 2016 Ma Yanyan problem Description: No input Description: No output description: result; */#include <iostream>using namespace 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. --"<<j<<endl;}    ; Class Derived2:virtual public base{public:    Derived2 (Char I,char j): Base (i) {        cout<< "Derived2 Constructor. --"<<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:


Summary of Knowledge points:

Derived1 and Derived2 both inherit base, and Myderived inherits Derived1 and Derived2, and for base two semantics, base is set to virtual base class, and virtual is added before inheriting mode. Only the constructor of the virtual base class is called by the most derived constructor, and the other base classes of the derived class are ignored for calls to the constructor of the virtual base class, the constructor of base is called, and then it is output sequentially in the order of the constructors.

Tenth week-Read the program

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.