Multiple inheritance example

xiaoxiao2021-03-06  40

#include using namespace std; typedef int NET2K1; enum COLOR {red, green, blue, yellow, white, black, brown}; class net2k {public: net2k (COLOR color, NET2K1 height); virtual ~ net2k () {cout << "The first class destructor! / n";} Virtual void windows () const {cout << "The first virtual function of the first class!"; Virtual Net2k1 getHeight () Const {RETURN ITSHEIGHT;} Virtual color getColor () const {return itscolor;} private: Net2k1 itsheight; color itscolor;}; // first class

Net2k :: Net2k (Color Color, Net2k1 Height): ITSCOLOR (Color), ITSHEIGHT (HEIGHT) // Initialized Variable {COUT << "First Class Initialization Variable / N";}

Class Bird // Declaration of Second Class Start {Public: Bird (Color, Bool); Virtual ~ Bird () {cout << "The sect of the second class" Download Adobe Reader;} Virtual Void Chirp () Const {COUT << "Second Class Dian Function";} Virtual Void Fly () const {cout << "The second class of the second class has a virtual constructor-virtual function!";} Virtual color getColor () CONST {Return Itscolor; Virtual Bool getMigration () const {return itsmigration;} private: color itscolor;

Bird :: Bird (Color Color, Bool Migrate): ITSCOLOR (color), ITSMigration (migrates) {cout << "second class initialization variable / n";}

Class PegaSus: public net2k, public bird // derived from multiple base classes {public: void chirp () const {windows ();} // overwrite the fictional creation functions of the second base class PEGASUS (Color, Net2k1, Bool Long); ~ pegasus () {cout << "Directive class destructor / n";} Virtual long getnumberbelievers () const {return itSnumberbelievers;} private: long itSnumberbelievers;};

PegaSus :: Pegasus (Color Acolor, Net2k1 Height, Bool Migrates, Long Numbelieve): Net2k (Acolor, Height), Bird (Acolor, Migrate), ITSNumberbelievers (Numbelieve) {cout << "Derived Print Output ... / N ";

转载请注明原文地址:https://www.9cbs.com/read-78533.html

New Post(0)