A
Q. What is the output of the following C++ code?
Code:
#include<iostream>
using namespace std;
class A {
private:
int val;
public:
A(int v = 0) : val(v) {}
void display() { cout << "val = " << val << endl;}
};
class B {
private:
int val;
public:
B(int v) : val(v) {}
operator A() const { return A(val); }
};
void f(A a)
{ a.display(); }
int main() {
B b(5);
f(b);
f(55);
return 0;
}
using namespace std;
class A {
private:
int val;
public:
A(int v = 0) : val(v) {}
void display() { cout << "val = " << val << endl;}
};
class B {
private:
int val;
public:
B(int v) : val(v) {}
operator A() const { return A(val); }
};
void f(A a)
{ a.display(); }
int main() {
B b(5);
f(b);
f(55);
return 0;
}
- Correct Answer - Option(B)
- Views: 26
- Filed under category C++
- Hashtags:
Discusssion
Login to discuss.