C++ Programming - Functions - Discussion

Discussion Forum : Functions - General Questions (Q.No. 4)
4.
Which of the following statement is correct?
Two functions having same number of argument, order and type of argument can be overloaded if both functions do not have any default argument.
Overloaded function must have default arguments.
Overloaded function must have default arguments starting from the left of argument list.
A function can be overloaded more than once.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Hrudwik said:   7 years ago
Since using const, it must have a default argument. Which against option A.

Hope this helps.

Asd said:   8 years ago
Why A is not true? We can overload by using const!

Satya said:   10 years ago
void addition(int a,int b,int c=3, int d=4);
void addition(int,int); Not allowed by the compiler.

Why do you need the above two functions when all your commands can be executed by the first function that is

void addition(int a,int b,int c=3, int d=4);

This can execute all the below calls.
additon(1,2,3,2);
addition(6,7,8);
addition(5,1);

Varsharani buktare said:   1 decade ago
Actually , I have one doubt that suppose prototype of some overloaded functions.

void addition(int a,int b,int c=3, int d=4);
void addition(int,int);

& In our program we write the function call like:

additon(1,2,3,2);
addition(6,7,8);
addition(5,1); // Which function going to call the compiler here?
Or compiler get the ambiguity?
What happens exactly?

Post your comments here:

Your comments will be displayed after verification.