C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - Programs (Q.No. 12)
12.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
    IndiaBix(short ss)
    {
        cout<< "Short" << endl;
    }
    IndiaBix(int xx)
    {
        cout<< "Int" << endl;
    }
    IndiaBix(float ff)
    {
        cout<< "Float" << endl;
    }
    ~IndiaBix() 
    {
        cout<< "Final";
    }
};
int main()
{
    IndiaBix *ptr = new IndiaBix('B');
    return 0; 
}
The program will print the output Short .
The program will print the output Int .
The program will print the output Float .
The program will print the output Final .
None of the above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
14 comments Page 2 of 2.

Raju said:   1 decade ago
Why this happens? Why it does not treat it short or float?

Arvind said:   1 decade ago
There is no overloaded constructor for char, so compiler will treat 'B' as 66 (ASCII value of B) due to implicit type conversion from char to int.

Raju said:   1 decade ago
Here pass in char B but char argument is not passed their so by print INT.

Raju said:   1 decade ago
Why not constructor with 'short' argument was selected. Could somebody please explain?


Post your comments here:

Your comments will be displayed after verification.