D
Q. What is the output of the following C++ 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; }
Since there is a conversion constructor in class A, an integer value can be assigned to objects of class A and the function call f(55) works correctly. In addition, there is an overloaded conversion operator in class B, so we can call f() with objects of class B.
You must be Logged in to update hint/solution
Be the first to start discuss.
Q. Which of the following is used to terminate the function declaration in C++?
Q. _______ is correctly declares an array?
Q. What is the output of the following C++ code?
Q. ‐‐‐‐‐‐‐ are used for comparing two conditions or to write a compound condition.
Q. An exceptio in C++ can be generated using which keywords.
Q. Which of the following operators cannot be overloaded in C++?
Q. Find the output of the following program.
Q. What is the output of the following C++ code?
Q. How C++ compiler does differ between overloaded postfix and prefix operators?
Discusssion
Login to discuss.