Let's look at an example:
Class base {public: Virtual void mf1 () = 0; virtual void mf1 (INT) {} virtual void mf2 () {} void mf3 () {} void mf3 (double) {}}; class derived: public base {public: Virtual void mf1 () {}void mf3 () {} void mf4 (){}};
The behavior of this code will surprise every C ++ programmer who is facing it for the first time, all functions named mf1 and mf3 in base class are hidden by mf1 and mf3 functions in derived class. From the perspective of name search, base: mf1 and base: mf3 are no longer inherited by derived!
Derived D; int X; D. mf1 (); D. mf1 (x); // error! Because derived: mf3 hides base: mf1d. mf2 (); D. mf3 (); D. mf3 (x); // error! Because derived: mf3 hides base: mf3
The above behavior violates the is-a relationship between base and derived class, so you almost always have to overturn C ++'s default masking behavior for "inherited names. You can use the using declarative method to achieve the goal:
Class derived: public base {public: using base: mf1; // set the using base: mf3 of mf1 and mf3 in the base class; // all objects are visible in the derived scope. Virtual void mf1 () {} void mf3 () {} void mf4 (){}};
Note:
One of the most important rules for Object-Oriented Programming with C ++ is that public inheritance (Public inheritance) implies a "is-a" (yes) relationship.
From Objective C ++