C++: rationale behind hiding rule

前端 未结 5 1000
旧时难觅i
旧时难觅i 2020-11-27 20:15

What\'s the rationale behind the hiding rule in C++?

class A { void f(int); }
class B : public A { void f(double); } // B::f(int) is hidden
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 20:54

    i don't know the original rationale, but since hide or not hide are about equally bad choices wrt. to functions, i'm guessing the rationale is to have uniform rules: the same as for names defined in nested curly-braces scopes.

    the hiding helps you in some ways.

    adding a method to a base class will by default not affect overload resolution for a derived class.

    and you do not run afoul of overload resolution by some mishap directing your call with say argument false, to a base class method with formal argument void*. such things.

    cheers & hth.,

提交回复
热议问题