C++ Programming - Functions - Discussion

Discussion Forum : Functions - Programs (Q.No. 39)
39.
What will be the output of the following program?
#include<iostream.h> 
class Base
{
    int x, y; 
    public:
    Base() 
    {
        x = y = 0; 
    } 
    Base(int xx)
    {
        x = xx;
    }
    Base(int p, int q = 10)
    {
        x = p + q;
        y = q; 
    } 
    void Display(void)
    {
        cout<< x << " " << y << endl;
    } 
}objDefault(1, 1);

class Derived: public Base
{
    Base obj; 
    public:
    Derived(int xx, int yy): Base(xx, xx + 1)
    { }
    Derived(Base objB = objDefault)
    { } 
}; 
int main()
{
    Derived objD(5, 3);
    Derived *ptrD = new Derived(objD);
    ptrD->Display();
    delete ptrD;
    return 0; 
}
3 2
8 3
11 6
11 10
The program will not compile successfully.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Vivek v said:   8 months ago
This will be an overloading function, right?

Anyone, please explain it clarely.

BartoszT said:   6 years ago
Is it ambiguity?

Base(int xx)
Base(int p, int q = 10)

Phong said:   1 decade ago
Derived(5:3) : Base(5,6).
x = 5 + 6 = 11.
y = 6.

Raj said:   1 decade ago
How ? Could anybody please explain ?

Post your comments here:

Your comments will be displayed after verification.