1. 程式人生 > >C++ 名字衝突和繼承

C++ 名字衝突和繼承

15.5.2. Name Collisions and Inheritance

Note:A  derived-class member with the same name as a member of the base class hides direct access to the base-class member.

Using the Scope Operator to AccessHidden Members

We can access a hidden base-class member by using the scope operator:

structDerived : Base {

intget_base_mem() { return Base::mem; }

};

Best Practices:When designing a derived class, it is best to avoid name collisions with members of the base class whenever possible.