home *** CD-ROM | disk | FTP | other *** search
- // "Multiple Inheritance 2" -- DOUBLES2.HPP
- /*
-
- C++ program that illustrates the following
- small class hierarchy:
-
- /-aString--\
- | |
- | |
- | |
- | |
- | |
- anInt LeDouble
- | |
- | |
- \----------/
- |
- |
- |
- aDouble
-
- */
-
- #include <iostream.h>
- #include <math.h>
- #include <string.h>
-
- const int STR_LEN = 31;
-
- class aString
- {
- public:
- aString()
- { someText[0] = '\0'; }
- void setText(const char* pText)
- { strcpy(someText, pText); }
- void showText()
- { cout << someText << "\n"; }
-
- protected:
- char someText[STR_LEN];
- };
-
- // uses the virtual keyword to delcare anInt
- // since anInt has the same
- // ancestor as LeDouble: aString
-
- class anInt : virtual public aString
- {
- public:
- anInt() : aString()
- { anIntValue = 0; }
- void setInt(int IntValue)
- { anIntValue = IntValue; }
- void showInt()
- { cout << anIntValue << "\n"; }
-
- protected:
- int anIntValue;
- };
-
- // uses the virtual keyword to delcare LeDouble
- // since LeDouble has the same
- // ancestor as anInt: aString
-
- class LeDouble : virtual public aString
- {
- public:
- LeDouble() : aString()
- { aDoubleValue = 0; }
- void setDouble(double DoubleValue)
- { aDoubleValue = DoubleValue; }
- void showDouble()
- { cout << aDoubleValue << "\n"; }
-
- protected:
- double aDoubleValue;
- };
-
- // uses the virtual keyword to delcare aDouble
- // since it inherits from anInt and LeDouble, which
- // share a common ancestor: aString
-
- class aDouble : virtual public anInt,
- virtual public LeDouble
- {
- public:
- aDouble() : anInt(), LeDouble() { }
- };
-
-