The scoping rule will overshadow the variables in the parent class and you can't access them; so they become useless.
Consider the following 2 classes where myNewClass defines the same function func1(int) that is also found in its parent class:
class myOldClass { public: int i1; void func1(int i) { i1 = i1 + i; } }; |
class myNewClass : public myOldClass { public: int i2; void func1(int i) { i2 = i2 + 1000*i; } }; |
Let us consider a program with one variable and one pointer of each type:
myOldClass A; myOldClass *ptr1; myNewClass B; myNewClass *ptr2; A.func1(4); // Invokes myOldClass::func1() B.func1(4); // Invokes myNewClass::func1() ptr1 = &A; ptr1->func1(4); ptr1 = &B; ptr1->func1(4); |
 
 
This outcome is what we should expect, afterall, we are evaluating the same expression !!!
I am only illustrating what you have learned so far to make the difference in the next example more evident.
class myOldClass { public: int i1; virtual void func1(int i) { i1 = i1 + i; } }; |
class myNewClass : public myOldClass { public: int i2; virtual void func1(int i) { i2 = i2 + 1000*i; } }; |
Let us consider the same program with one variable and one pointer of each type:
myOldClass A; myOldClass *ptr1; myNewClass B; myNewClass *ptr2; A.func1(4); // Invokes myOldClass::func1() B.func1(4); // Invokes myNewClass::func1() ptr1 = &A; ptr1->func1(4); ptr1 = &B; ptr1->func1(4); |
 
 
This outcome is what we do NOT expect.... a different function was invoked depending on the circumstance (more precisely, depending on which type of variable ptr1 was pointing to....