protected Vererbung
-
class x{ public: void foo(){}; }; class y: protected x { // was bedeutet protected public: void foo1(){foo(); } }; class z:y { public: void foo2(){foo();} };
was bedeudet protected Vererbung nochmal ?
-
Seufz
. Für so eine Frage bemühst du ein Forum?
Google: protected inheritance C++
Erster Treffer:
C++ FAQ-Lite schrieb:
[24.5] How is protected inheritance related to private inheritance?
Similarities: both allow overriding virtual functions in the private/protected base class, neither claims the derived is a kind-of its base.
Dissimilarities: protected inheritance allows derived classes of derived classes to know about the inheritance relationship. Thus your grand kids are effectively exposed to your implementation details. This has both benefits (it allows derived classes of the protected derived class to exploit the relationship to the protected base class) and costs (the protected derived class can't change the relationship without potentially breaking further derived classes).
-
Innerhalb von Klassse y kann auf x::foo() zugegriffen werden. Von außen kann aber nicht auf x::foo() zugegriffen werden.