C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 34)
34.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x;
float y;
public:
IndiaBix(int x)
{
x = x;
}
IndiaBix(int p = 0, int q = 10)
{
x = p += 2;
y = q * 1.0f;
}
void SetValue(int &y, float z)
{
x = y;
y = (int)z;
}
void Display(void)
{
cout<< x;
}
};
int main()
{
int val = 12;
IndiaBix objBix(val);
IndiaBix objTmp();
objBix.SetValue(val, 3.14f);
objBix.Display();
return 0;
}
Discussion:
6 comments Page 1 of 1.
Rana said:
7 years ago
There is two overloaded function IndiaBix(int x) and IndiaBix(int p = 0, int q = 10).
If you pass val parameter in constructor(IndiaBix objBix(val)). Then the compiler will get confused to call the function. So it will give an ambiguous error.
If you pass val parameter in constructor(IndiaBix objBix(val)). Then the compiler will get confused to call the function. So it will give an ambiguous error.
Neha said:
1 decade ago
Default constructor is not defined, as it should be defined if user defined constructor is present.
Rabins rai said:
7 years ago
Here we can not send val we have to specify what we are passing.
Honiy said:
8 years ago
In the single parameterised constructor it should be this x=x.
Sandeep said:
1 decade ago
Ambiguous call to overloaded function.
Jitesh said:
1 decade ago
How ambiguity occur?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers