In C++, what is the difference between method overloading and method overriding?

Author Topic: In C++, what is the difference between method overloading and method overriding?  (Read 2047 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 158
  • Karma: 0
    • Hot Shaper
Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.


Offline TomClarke

  • Trade Count: (0)
  • Hero Member
  • *****
  • Thank You 50
  • Posts: 874
  • Karma: 0
  • Gender: Male
    • Custom Writing Service & Content Marketplace
Method overloading happens i the same class shares the same method name but each method should have different number of parameters having different types and order. But in the method overriding derived class have the same method with same name and exactly the same number and type of parameters and same return type as a parent class. Also method overloading happens at compile time while overriding happens at runtime.
Your ideas, our writings - Writology.com

Offline abhik143

  • Trade Count: (0)
  • Newbie
  • *
  • Thank You 0
  • Posts: 2
  • Karma: 0
1.In overloading,there is a relation ship between methods available in the same class where as in overridding,there is relationship between a super class method and subclass method.
2.Overloading doesn't block inheritence from the superclass where as overridding blocks inheritence.
3.In overloading,seperate methods share the same name where as in overridding,subclass methods replaces the superclass.
4.Overloading must have different method signatures where as overriding must have same signature.

Example

1. Overriding
public class MyBaseClass
{
    public virtual void MyMethod()
    {
        Console.Write("My BaseClass Method");

    }
}
public class MyDerivedClass : MyBaseClass
{
    public override void MyMethod()
    {
        Console.Write("My DerivedClass Method");

    }
}

2. Overloading
int add(int a, int b)
int add(float a , float b)

Reference:- newbielink:http://tech.queryhome.com/52366/difference-between-overloading-and-overriding-in-c?show=52370#a52370 [nonactive]

Offline alisaa

  • Trade Count: (0)
  • Newbie
  • *
  • Thank You 0
  • Posts: 4
  • Karma: 0
    • Nationkart
Method Overloading : When more than one method shares the same name in the class but having a different signature.
Method Overriding : When a method of base class is re-defined in the derived class having the same signature.

Method Overloading : It is a compile-time polymorphism.
Method Overriding : It is a run time polymorphism.
newbielink:http://nationkart.com/blog/how-to-start-multi-vendor-e-commerce-website/ [nonactive]

 

Related Topics

  Subject / Started by Replies Last post
6 Replies
2072 Views
Last post 09-23-2011, 13:18:35
by Johan68
38 Replies
5888 Views
Last post 09-30-2013, 05:42:55
by sonusmith
0 Replies
1306 Views
Last post 03-19-2012, 06:39:02
by Vinil
28 Replies
7205 Views
Last post 04-25-2016, 13:09:50
by vishistsingh
6 Replies
3005 Views
Last post 10-24-2013, 07:10:51
by alexloxton