C++/c++

Advertisement


Question
what is function overriding and function overloading in c++?
what are the differences between them?
sir please give examples for those two concepts

Answer
Hi Rajendra

First try n understand the basic difference between the two

OVERLOADING:
Both the function has same name but difference signature e.g.
void function_name(int x)
int function_name(float y)
NOTE: Function name should be same but the passing parameters to the function should be different. You cannot keep exactly same signature for any two the methods. Functions cannot be separated on the basis of its return type e.g.
Example #1(Functions having exactly same signature)
void function_name(int x) //WRONG
void function_name(int y) //WRONG
Example #2(Functions separated on the basis of return type)
void function_name(int y) //WRONG
int function_name(int y) //WRONG

OVERRIDING:
In this case both have the exactly same signature but you need to have class for overriding. A method in the base class is overridden in the child class with some added or extra functionality e.g.
class Base {
void function_name(){
printf("Base");
}
};
class Derived extends Base{
void function_name(){
printf("Derived");
}
};
NOTE: In this case the method name function_name from the base class is derived and then overridden in the child class, this comes handy for inheritance.

Please lemme know in case if you have an doubt regarding the same.

regards
Joydeep Bhattacharya
http://www.scodz.com

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

TSR, Socket and Very Complex Mathematical Problem

Experience

Worked on many OOP projects with design patterns

Organizations
http://www.scodz.com

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Awards and Honors
Being a proud owner of a website of programming called http://www.scodz.com

Past/Present Clients
http://www.funforu.com http://www.dhoondho.com http://analysingc.50webs.com

©2016 About.com. All rights reserved.