Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is overriding and overloading in polymorphism?

Thanks in advance.
Posted
Updated 5-Jul-10 23:56pm
v2

Overloading - Two functions having same name, but with different type and/or number of arguments. There are two types of overloading function overloading and operator overloading.
Overriding - When a function of base class is re-defined in the derived class.

overloading must have different method signatures where
as overriding must have same signature.

Example:
class A
{
   void OverloadedMethod(int a);
   void OverloadedMethod(float a);
   void OverloadedMethod(int a, int b);
   void OverloadedMethod(float a, int b);
   //int OverloadedMethod(int a); Not possible
};
class Base
{
  virtual void OverridenMethod( int a);
};
class Detived : Base
{
  virtual void OverridenMethod( int a);
};


Edited by Aescleal: Tidied up the syntax so it'd compile and removed an innacurate statement from the blurb at the start (return types play no part in overload resolution so overloaded methods don't have to return the same thing).
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900