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

Started by chinmay.sahoo, 03-10-2016, 05:05:14

Previous topic - Next topic

chinmay.sahooTopic starter

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.


TomClarke

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.


abhik143

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]
  •  

alisaa

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]
  •