Private inheritance means something entirely different (see ), and protected inheritance is something whose meaning eludes me to this day
there is no one ideal design for all software. The best design depends on what the system is expected to do
The is-a relationship is not the only one that can exist between classes. Two other common inter-class relationships are "has-a" and "is-implemented-in-terms-of."
Item[33]
This means that if you inherit from a base class with overloaded functions and you want to redefine or override only some of them, you need to include a using declaration for each name you'd otherwise be hiding.
class Base { private: int x; public: virtual void mf1() = 0; virtual void mf1(int); virtual void mf2(); void mf3(); void mf3(double); ... };
class Derived: public Base { public: using Base::mf1; // make all things in Base named mf1 and mf3 using Base::mf3; // visible (and public) in Derived's scope
virtual void mf1(); void mf3(); void mf4(); ... };
|
a using declaration makes all inherited functions with a given name visible in the derived class.
class Base { public: virtual void mf1() = 0; virtual void mf1(int); ... // as before };
class Derived: private Base { public: virtual void mf1() // forwarding function; implicitly
{ Base::mf1(); } // inline (see Item 30) ... };
...
Derived d; int x; d.mf1(); // fine, calls Derived::mf1 d.mf1(x); // error! Base::mf1() is hidden
|
阅读(602) | 评论(0) | 转发(0) |