next up previous contents index
Next: Templates und Vererbung Up: 50 Ways to Improve Previous: Modelliere ``hatein'' durch Elemente

Private Vererbung

 

Objekte abgeleiteter Klassen können bei privater Vererbung nicht in solche der Basisklasse umgewandelt werden:

    class a
    { int aa;
    public:
      a(int i=0): aa(i) {}
    };
    class b : private a
    { int bb;
    public:
      b(int i=0): bb(i) {}
    };
    int main()
    { b vb(20);
      a* pa = &vb;
    }

Compiler:

error: no standard conversion of b* to a*
error: cast: b* -> base a*; private base class

Darüberhinaus wird nur die Implementierung der Elementfunktionen vererbt, nicht die Schnittstelle

tex2html_wrap_inline5173 Private Vererbung modelliert nicht istein sondern ist-implementiert-durch.  


next up previous contents index
Next: Templates und Vererbung Up: 50 Ways to Improve Previous: Modelliere ``hatein'' durch Elemente

Peter Pfahler, 1997