C++ inheriting member functions of the same type signature (shadowing)
<pre><code> // Shadowing

 #include &lt;iostream&gt;
 using namespace std;
 const int MNAME = 30;
 const int M  = 13;

 class Person {   // Base Class
     char person[MNAME+1];
   public:
     void set(const char* n);
     void display(ostream&amp;) const;
   protected:
     const char* name() const;
 };

 void Person::set(const char* n) {
     strncpy(person, n, MNAME);
     person[MNAME] = '\0';
 }

 void Person::display(ostream&amp; os) const {
     os &lt;&lt; person &lt;&lt; ' ';
 }

 const char* Person::name() const { return person; }

 class Student : public Person { // Derived
     int no;
     char grade[M+1];
   public:
     Student();
     Student(int, const char*);
     void display(ostream&amp;) const;
 };

 Student::Student() {
     no = 0;
     grade[0] = '\0';
 }

 Student::Student(int n, const char* g) {
     // see p.61 for validation logic
     no = n;
     strcpy(grade, g);
 }

 void Student::display(ostream&amp; os) const {
     os &lt;&lt; name() &lt;&lt; ' '
        &lt;&lt; no &lt;&lt; &lt;&lt; ' ' &lt;&lt; grade &lt;&lt; endl;
 }

 int main() {
     Person person;
     Student student(975, "ABBAD");

     student.set("Harry");
     student.display(cout); // Harry 975 ABBAD

     person.set("Jane Doe");
     person.display(cout); // Jane Doe
 }
</code></pre>

<blockquote>
  <p>The first call to display() (on student) calls the Student version of
  display().  The second call to display() (on person) calls the Person
  version of display().  The derived version of display() shadows the
  base version on the student object.  The base version executes on the
  person object.</p>
</blockquote>

<p>I don't understand what shadowing is then. I realize that both classes have the same display function defined, and obviously if you call student.display and person.display its going to call them accordingly. So what does this mean:  </p>

<blockquote>
  <p>The derived version of display() shadows the base version on the
  student object.  The base version executes on the person object.</p>
</blockquote>

<p>I don't understand shadowing.</p>

<p>source: <a href="https://scs.senecac.on.ca/~btp200/pages/content/dfunc.html" rel="nofollow">https://scs.senecac.on.ca/~btp200/pages/content/dfunc.html</a>
Inheritance - Functions of a derived class</p>
