The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
712 views

Which one of the following is correct for overloaded functions in C++?

  1. Compiler sets up a separate function for every definition of the function.
  2. The compiler does not set up a separate function for every definition of the function.
  3. Overloaded functions cannot handle different types of objects.
  4. Overloaded functions cannot have the a same number of arguments.
asked in Others by Veteran (363k points) | 712 views

2 Answers

+1 vote
Best answer
When you call an overloaded function or operator, the compiler determines the most appropriate definition to use by comparing the argument types you used to call the function or operator with the parameter types specified in the definitions. The process of selecting the most appropriate overloaded function or operator is called overload resolution.

Ans: (A)
answered by Active (3.9k points)
selected by
0

just take a smaal example:-

int sum(int ,int);

int sum(float,float,float);

int main()

{

float x=5.5,y=6.5;

float m= sum(x,y);

}

 

now my doubt is when i passed x,y to sum ;x,y are of float type but there is no fn def which takes 2 float parameters;

therefore x,y will be degraded to int and int sum will be returned!

so no fn def is there for 

sum(float,float)

but when needed it is degraded to sum(int,int)

hence,shouldn't the option be (B).

0 votes

The compiler sets up a separate function for every definition of function this is due to overload function in C++. For more information in overloading function. Refer:Function Overloading in C++ So, option (A) is correct.

answered by (65 points)

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,685 questions
48,650 answers
156,447 comments
63,961 users