I have a question about how to access the member with the same name with inheritance. For example,
class Base {
public:
int i;
};
class Derived1 : public Base {
public:
int i;
// how to access the i in the base class here?
};
int main() {
Derived1 d;
cout<<d.i; //which is it is?
//how to access the different i here?
}
d.iin your example refers to theiin the derived class.You can refer to the base class
iby qualifying it with the base class name:In general, it’s a bad idea to have derived classes with members having the same name as members in base classes.