Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Simple PHP, Development, PHP Programming lessnos

Function overloading - C++

Type: Code Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Level: Expert Networking, Programming and Graphics - Tutorials Networking, Programming and Graphics - Tutorials Networking, Programming and Graphics - Tutorials 
Networking, Programming and Graphics - Tutorials
Date: 2006-Dec-08
Networking, Programming and Graphics - Tutorials
Visited: 22241 times
Networking, Programming and Graphics - Tutorials
Rating: Networking, Programming and Graphics - Tutorials
Networking, Programming and Graphics - Tutorials
Author: Alex Tutorialized

This tutorial will explain function overloading.
In function overloading, the function is said to be overloaded when same name is given to different functions. However, the functions will differ at least in any one of the these. The number of parameters, the data type of parameters, the order of appearance these three together are referred to as the function signature. While overloading a function, the return types of the function need not differ.

1. Functions differ in function signature.
2. Return types of functions need not differ.
How-to check my Windows version - Windows XP

#include<conio.h>
#includde<iostream.h>

class arith {
public:
    
void calc(int num1)

{
count<<"\n\nSquare of a given number: " <<num1*num1 <<endl;
}

    
void calc(int num1int num2 )

{
count<<"\n\nSquare of a given number: " <<num1*num2 <<endl;
}
};


void main() //begin of main function
{
clrscr();
arith a;
a.calc(5);
a.calc(6,7);
getch();
}
The code depicts function overloading. There are two functions with the same name calc. In the main function, when the function calc is invoked using the object a, depending up on the type and number of parameters, the compiler binds the call to the function. Hence, when calc(5) is called, the compiler checks for the function matching the parameter type. So calc(int num l) will be invoked and parameter will be passed to the function at runtime and output displayed. Similarly, when calc(6,7) is called, it looks for the same function with two integers as parameter and bind the respective function to the call.
Basic stream classes

#include<conio.h>
#includde<iostream.h>

//this is basic function classes for Input Output stream.
And you are done. Function in this class work with different way according to values of the argument which they accept. This is call function overloading. Output for this tutorial you may see in down box.

I hope this tutorial is useful for you.

To see more Tutorials with different programing language: Sending e-mails with PHP mail() function click this link.

Output for this tutorial is:

Square of a given number is25 (5*5)
Multiplication of given number is42 (6*7)
Rate this tutorial:                    
Post Comment

    • ( youandashish [ at ] gmail . com ),

      posted on 2009-Jun-24 | 06:59:00 AM
      i want many programms in that function overloding in c
Need a specific tutorial? Do not hesitate and submit a request!
Your e-mail: