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
simple shopping cart

Employ operator () instead of operator[]. While you have multiple subscripts, the cleanest way to do it is along with operator () instead of with operator[]. The reason is that

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Simpson's Rule is a more accurate method of numerical integration than the method described in class. Using Simpson's Rule, the integral of a function f between a and b is approxim

Implementation of the Stack class in C++: How to implement stack class in c++. int Stack::push(int elem) {    if (top    {       list[top++] = elem;       r

Sorted directory - C++ program: Write a program in c to sorting a directory. int main( int argc, char *argv[] ) {     if( argc 3 )         {         cerr

Question: (a) Explain a linked list. (b) Describe the three different types of linked list with the help of diagrams. (c) Give two advantages and two disadvantages

How can I handle a constructor that fails?

Define Multi File Program? While writing large programs we must divide programs up into modules. These would be separate source files and the main() function would be in one fi

how can I find the GCD of 2 given numbers using Euclidean Algorithm ?