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.