This document discusses method overloading in C++, which allows creating multiple functions with the same name as long as they have different parameters. It provides examples of overloading functions based on different data types and number of parameters. The document also includes an example program demonstrating overloading functions to calculate the area of different shapes.
2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
3. Typing Speed: 20
Typing Speed: 21
Muhammed shafi
shafi3949@gmail.com
Shafi breeze
Shafi breeze
in.linkedin.com/in/profilena
me
9961073949
5. Method overloading
• Method overloading is a feature of C++ that
allows us to create multiple functions with the
same name, so long as they have different
parameters.
6. (a) sum (int,int,int);
sum (int,int);
• Here, the above function can be overloaded. Though
data type of arguments in both the functions are
similar but number of arguments are different.
(b) sum (int,int,int);
sum (float,float,float);
7. • Function overloading is the process of
using the same name for two or more
functions.
• The secret to overloading is that each
redefinition of the function must use
either• different types of parameters
• different number of parameters.
8. Example
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
#include<iostream.h>
#include<conio.h>
float area(float); //function prototype
int area(int);
int area(int,int);
void main()
{
int a,l,b;
float r;
cout<<"Enter the radius of circle"<<endl;
cin>>r;
cout<<"Enter the side of square"<<endl;
cin>>a;
cout<<"Enter the length and breadth of rectangle"<<endl;
cin>>l>>b;
cout<<"Area of circle is "<<area(r)<<endl;
cout<<"Area of square is "<<area(a)<<endl;
cout<<"Area of rectangle is "<<area(l,b)<<endl;
getch();
}
11. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550