home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / doubles2.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  1.8 KB  |  91 lines

  1. // "Multiple Inheritance 2" -- DOUBLES2.HPP
  2. /*
  3.  
  4.    C++ program that illustrates the following
  5.    small class hierarchy:
  6.  
  7.          /-aString--\
  8.          |          |
  9.          |          |
  10.          |          |
  11.          |          |
  12.          |          |
  13.       anInt        LeDouble
  14.          |          |
  15.          |          |
  16.          \----------/
  17.               |
  18.               |
  19.               |
  20.            aDouble
  21.  
  22. */
  23.  
  24. #include <iostream.h>
  25. #include <math.h>
  26. #include <string.h>
  27.  
  28. const int STR_LEN = 31;
  29.  
  30. class aString
  31. {
  32.   public:
  33.     aString()
  34.       { someText[0] = '\0'; }
  35.     void setText(const char* pText)
  36.       { strcpy(someText, pText); }
  37.     void showText()
  38.       { cout << someText << "\n"; }
  39.  
  40.   protected:
  41.     char someText[STR_LEN];
  42. };
  43.  
  44. // uses the virtual keyword to delcare anInt 
  45. //  since anInt has the same
  46. // ancestor as LeDouble: aString
  47.  
  48. class anInt : virtual public aString
  49. {
  50.   public:
  51.     anInt() : aString()
  52.       { anIntValue = 0; }
  53.     void setInt(int IntValue)
  54.       { anIntValue = IntValue; }
  55.     void showInt()
  56.        { cout << anIntValue << "\n"; }
  57.  
  58.   protected:
  59.     int anIntValue;
  60. };
  61.  
  62. // uses the virtual keyword to delcare LeDouble
  63. //  since LeDouble has the same
  64. // ancestor as anInt: aString
  65.  
  66. class LeDouble : virtual public aString
  67. {
  68.   public:
  69.     LeDouble() : aString()
  70.       { aDoubleValue = 0; }
  71.     void setDouble(double DoubleValue)
  72.       { aDoubleValue = DoubleValue; }
  73.     void showDouble()
  74.        { cout << aDoubleValue << "\n"; }
  75.  
  76.   protected:
  77.     double aDoubleValue;
  78. };
  79.  
  80. // uses the virtual keyword to delcare aDouble 
  81. //  since it inherits from anInt and LeDouble, which
  82. // share a common ancestor: aString
  83.  
  84. class aDouble : virtual public anInt,
  85.                 virtual public LeDouble
  86. {
  87.   public:
  88.     aDouble() : anInt(), LeDouble() { }
  89. };
  90.  
  91.