Objects of the same name in base and derived class not getting flagged as an error
c++, inheritance
Solution
It isn't getting flagged as an error because it's not an error. There's nothing that says you can't have members in a derived class that are named the same as members in a base class.
If you have an object `obj` of type `Derived`, then `obj.m_Pants` refers to the `m_Pants` in `Derived`. If you want to refer to the base member, you can do so using `obj.Base::m_Pants`.
If you are in a member function of `Base` or have a `Base*` that points to an object of type `Derived`, then `m_Pants` always refers to the member of `Base`, because in those contexts there is no knowledge of the class `Derived` and its members.
Well, it's not a code error; it's almost certainly a design error.
Problem
``` class Base { public: type1 m_Pants; }; class Derived : Base { public: type2 m_Pants }; ``` This essentially didn't get flagged as an error, but was creating all kinds of clobbering and issues throughout a project. Does anyone know of a technicality that wouldn't flag this?