C++ Programming - References - Discussion

Discussion Forum : References - Programs (Q.No. 25)
25.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x, y; 
    public:
    IndiaBix(int xx = 0, int yy = 0)
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
    IndiaBix operator +(IndiaBix z)
    {
        IndiaBix objTemp;
        objTemp.x = x + z.x;
        objTemp.y = y + z.y;
        return objTemp; 
    }
};
int main()
{
    IndiaBix objBix1(90, 80); 
    IndiaBix objBix2(10, 20); 
    IndiaBix objSum; 
    IndiaBix &objRef = objSum; 
    objRef = objBix1 + objBix2; 
    objRef.Display(); 
    return 0; 
}
It will result in a runtime error.
It will result in a compile time error.
The program will print the output 9 4.
The program will print the output 100 100.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
6 comments Page 1 of 1.

Pavithra said:   7 years ago
Anybody explain it.
(1)

Karthik said:   8 years ago
Please explain this.

Virat said:   8 years ago
Explain it.

Szapi said:   7 years ago
I think it should be a compile time error, because cout is in namespace std.

Shiskey said:   6 years ago
Somebody, please explain it.

Killua said:   6 years ago
objBix1 , x = 90, y = 80;
objBix2, x = 10, y = 20;

There is an overloaded addition operator, which add x and y member of IndiaBix.
The result is obviously 100 and 100.

I thought this line of code is invalid at first, objRef is reference that initialized with objSum and could not refer to other object.
objRef = objBix1 + objBix2;

But it's ok, cause objBix1 and objBix2 were implicit converted from lvalue to rvalue at that point.

Post your comments here:

Your comments will be displayed after verification.