C + + Fifth experiment-------multiple inheritance

Source: Internet
Author: User

I. Questions and codes

[CPP] View plain copy/* * File name: Duojiicheng * Author: Xiatinghui * Completion Date: May 8, 2016 * version number: v1.0 * Description of task and solution method Section: No * Input Description: No * Description: Multiple inheritance * Program output: Slightly * problem analysis: slightly * algorithm design: Slightly */#include <string> #include &LT;IOSTREAM&G    T    using namespace Std;        Class Teacher {public:teacher (string nam,int a,string s,string tit);    void display ();        Protected:string name;        int age;        string sex;    string title;        }; Teacher::teacher (string nam,int a,string s,string Tit): Name (NAM), age (a), sex (s), title (tit) {} void Teacher:        :d Isplay () {cout<< "name:" <<name<<endl;        cout<< "Age:" <<age<<endl;        cout<< "Gender:" <<sex<<endl;     cout<< "title:" <<title<<endl;        } class Cadre {Public:cadre (string nam,int a,string s,string p);    void display ();        Protected:string name;        int age; string sEx      String post;        };    Cadre::cadre (String nam,int a,string s,string p): Name (NAM), age (a), sex (s), post (p) {} void Cadre::d isplay ()        {cout<< "name:" <<name<<endl;        cout<< "Age:" <<age<<endl;        cout<< "Gender:" <<sex<<endl;     cout<< "title:" <<post<<endl; } class Teacher_cadre:public Teacher,public cadre {public:teacher_cadre (string nam,int a,string s,st        Ring tit,string p,float W);    void Show ();    Private:float wage;        }; Teacher_cadre::teacher_cadre (String nam,int a,string s,string t,string p,float W): Teacher (nam,a,s,t), Cadre (nam,a,s       , p), wage (W) {} void Teacher_cadre::show () {Teacher::d isplay ();        cout<< "title:" <<cadre::p ost<<endl;    cout<< "Salary:" <<wage<<endl;        } int main () {Teacher_cadre Te_ca ("Zeng Hui", 42, "male", "Associate Professor", "director", 1534.5); Te_ca.show ();    return 0;     }


Ii. Results of operation


Third, experience

In the design of multi-inheritance, the concept is a bit confusing, after reading only understand, so-called multi-inheritance refers to the derived class has more than one base class, the relationship between the derived class and each base class can still be considered a single inheritance.

Iv. Summary of Knowledge points

Multiple inheritance As with single inheritance, when multiple inheritance constructs an object of a derived class, you also need to initialize the data members of the base class, the data members of the object, and the new data members.

C + + Fifth experiment-------multiple inheritance

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.