overloading vs overriding

后端 未结 4 1597
春和景丽
春和景丽 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:20

    Overloading is the process of defining multiple methods with identical names but different signatures; Overriding is when a function in a child class has an identical signature to a virtual function in a parent class.

    class Test {
      // Test::func is overloaded
      virtual void func(int x);
      virtual void func(double y);
    };
    
    class Child : public Test {
      // Child::func overrides Test::func
      virtual void func(int x); 
    };
    

提交回复
热议问题