Short Note : Function Overloading in C++ in hindi
Introduction
C++ language के एक से अधिक function को किसी शर्त के अनुसार एक ही नाम निर्धारित करने की सुविधा होती है। Function के एक ही नाम निर्धारित करने से प्रत्येक function में parameter की संख्या अलग अलग रखी जाती है। C++ Language का यह गुण फंक्शन ओवरलोडिंग (Function Overloading in hindi) कहलाता है। जब एक ही नाम वाले अनेक function अलग अलग प्रकार के parameters पर अलग अलग क्रियाएँ करते हैं तो function overloading use होता है।
Definition
Function Overloading different arguments और data type के साथ कई function को call करने की एक logical पद्धति है।
Declaration
निम्नलिखित दो function C++ में different है-
Float area (float radius);
Float area (float len, float wid);
यहाँ दोनों function के समान नाम हैं लेकिन argument की संख्या अलग अलग है। Function call की क्रिया के समय, C++ भाषा का compiler arguments की संख्या जाँचता है।
Program
#include<iostream.h>
#include<conio.h>
floaty area (float radius);
float area (float len, float wid);
void main()
{
char ch;
float radius, len,wid;
clrscr();
cout<<"\n enter C for circle and R for rectangle";
cin>>ch;
if ((ch=="C" :: (ch="C"))
{
cout<<"Enter radius"
cin>>radius;
cout<<"The area of the circle is : <<area (radius);
}
else
if (ch=="R") :: (ch=="R"))
{
cout<<"enter length :" cin>>len;
cout<<"enter width :" cin>>wid;
cout<<"The area of the rectangle :"<<area(len,wid);
}} // End of main function
float area pi=3.14159
return(pi*radius*radius);
float area(float len;float wid)
{
return(len*wid);
}
Advantage
1. Function को समझने, debug करने और आसानी से use करने में सहायता प्रदान करता है।
2. Code का आसान प्रबंधन।
3. समान operation के लिए different function नामों के उपयोग को रोकता है।