Functions overloading, C/C++ Programming

Functions Overloading

This a capability in which a C++ program can have several functions performing similar tasks on different data types. When an overloaded function is called, C++ selects the proper function by examining the
number, types and order of the arguments in the call.

Overloaded functions are distinguished by their signatures. A signature is a combination of function's name, and its parameter types.

The compiler encodes each function identifier with the number and types of its parameters to enable type safe linkage. Type safe linkage ensures that the proper overloaded function is called and the arguments conform to the parameters.

Creating overloaded functions with identical parameter list but different return types is a syntax error.

Example

Write a C++ program that uses overloaded functions to find squares of both an integer and double numeric values.

#include 
using namespace std;
int square(int);

double square(double);
int square  (int num)
{

return num*num;

 

}

double square  (double num)
{

return num*num;

 

}

int main  ()
{

int number1;

 

double number2;

 

cout<<"Enter an integer number"<

cin>>number1;

cout<<"Enter a floating point number"<>number2;

cout<<"The square of the integer number is: "
     <

cout<<"The square of the floating number is: "
     <

return  0;

Posted Date: 8/21/2012 11:52:27 AM | Location : United States







Related Discussions:- Functions overloading, Assignment Help, Ask Question on Functions overloading, Get Answer, Expert's Help, Functions overloading Discussions

Write discussion on Functions overloading
Your posts are moderated
Related Questions
Sorted directory - C++ program: Write a program in c to sorting a directory. int main( int argc, char *argv[] ) {     if( argc 3 )         {         cerr

Explain the Loop Statements in Computer Programming? 1. C gives you a choice of three kinds of loop, while, do while and for. 2. The while loop remain repeating an action until

Problem : Change to palindrome A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your ta


Write a program to act as an electronic safe. If the correct code has been entered the program should display "Safe Open".  If an incorrect code is input it should display "Alarm"

Given an char variable last that has been initialized to a lowercase letter, write a loop that displays all possible combinations of two letters in the range ''a'' through last. Th


You must write a program that can both decrypt and encrypt a single word that is entered by the user. The initial choice of encryption and decryption is left up to the user. Addi

Consider the following algorithm to generate a sequence of numbers. Start with an integer n. If n is even, divide by 2. If n is odd, multiply by 3 and add 1. Repeat this process wi

Is there any difficulty with the following : char*a=NULL; char& p = *a;? A: The result is indeterminate. You must never do this. A reference has to always refer to some object.