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 the correct syntax for defining a constant in C++?
Q. What is the output of this program?
Q. What is the output of this program?
Q. When a copy constructor may be called?
Q. ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ are conceptual things which exists only during the development process.
Q. Which class functions are called inline functions?
Q. Variable names must begin with ___
Q. The conditional compilation
Q. Which of the following is true about const member functions?
Discusssion
Login to discuss.