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; 
}
The program will print the output 2.
The program will print the output 12.
The program will report run time error.
The program will not compile successfully.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
6 comments Page 1 of 1.

Sandeep said:   1 decade ago
Ambiguous call to overloaded function.

Jitesh said:   1 decade ago
How ambiguity occur?

Neha said:   1 decade ago
Default constructor is not defined, as it should be defined if user defined constructor is present.

Honiy said:   8 years ago
In the single parameterised constructor it should be this x=x.

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.

Rabins rai said:   7 years ago
Here we can not send val we have to specify what we are passing.

Post your comments here:

Your comments will be displayed after verification.