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
Receive 3 numbers and display them in ascending order from smallest to largest ed#

I need to make a fractal trees in OpenGL C++ . The method used is to write a recursive function with cylinders of different sizes and angles to create the tree trunk and branches.


How can I handle a constructor that fails?


Ask questionByteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular

defining software crisis As the technology changes rapidly the requirement for the users' change, to part the growing demand of the user for trade,  business, and personal

PROGRAM TO FIND WHETHER A NUMBER IS ODD OR EVEN int main() { int number ; printf("Enter a whole number\n"); scanf("%d",&number); if(number % 2 == 0) printf("n


A student apears in exam of math, physics, and chemistry. Write a program to find the total marks aa student has aqueired find the average.