| Would you ever need to define a variable with the same name as some variable in the base class ??? |
The new variable should have a new name
You can't access the variables in the parent class; and they become useless.
class parent
{
public:
int i1;
parent()
{
i1 = 0;
}
void f1()
{
i1 = i1 + 1; // Access i1 in parent class
cout << "parent method f1" << endl;
cout << "parent's i1 = " << i1 << endl;
}
};
class child : public parent
{
public:
int i1;
};
int main(int argc, char **argv)
{
child x;
x.i1 = 1234; // Access i1 in child class
// i1 in parent class inaccessible !
x.f1(); // You need f1() to get to i1 in parent class
}
|