overloading vs overriding

后端 未结 4 1598
春和景丽
春和景丽 2021-01-02 02:00

I am a little confused over the two terminologies and would be glad to get some doubts clarified.

As I understand function overloading means having mult

4条回答
  •  暖寄归人
    2021-01-02 02:24

    • hiding is when a definition in a scope is not accessible due to a declaration in a nested scope or a derived class (3.3.7/1).

    A name can be hidden by an explicit declaration of that same name in a nested declarative region or derived class.

    • overriding is when a virtual member is replaced in a derived class (see 10.3/2)

    If a virtual member function vf is declared in a class Base and in a class Derived, derived directly or indirectly from Base, a member function vf with the same name and same parameter list as Base::vf is declared, then Derived::vf is also virtual an it overrides Base::vf.

    • overloading is when several declarations coexist for the same name in the same scope (13/1)

    When two or more different declarations are specified for a single name in the same scope, that name is said to be overloaded.

    • related, there is also the possibility of replacing operator new and delete from the standard library by one's own implementation (18.4.1.1/2, 18.4.1.1/6, 18.4.1.1/11, 18.4.1.2)

    So this is clearly a case of hiding.

提交回复
热议问题