next up previous
Mehrfachvererbung


Problem 2:
SubObjekt der indirekten Basisklasse mehrfach enthalten

 
                  class S {
                   int s;
                  public:
                   S(int _s) : s(_s){}
                   void printS()
                     { cout << s << "\n"; }
                  };

     class A: public S {               class B: public S {
       int x;                            char y;
     public:                           public:
       A(int _x)                         B(char _y)
       : S(111), x(_x){}                  : S(222), y(_y){}
       void printA()                      void printB()
         { cout << x << "\n"; }            { cout << y << "\n"; }
     };                                };

                  class C: public A, public B {
                    float z;
                  public:
                    C(int _A, char _B, float _z)
                    : A(_A), B(_B), z(_z){}
                    void printC()
                    { printS(); printA(); printB();
                      cout << z << "\n";
                    }
                  };


next up previous