Output of C++ Program | Set 2
Predict the output of below C++ programs.
i = 10
i = 20
Since there is a Conversion constructor in class A, integer value can be assigned to objects of class A and function call g(20) works. Also, there is a conversion operator overloaded in class B, so we can call g() with objects of class B.
Output: If integer takes 4 bytes, then 80.
Since b1 and b2 both inherit from class base, two copies of class base are there in class derived. This kind of inheritance without virtual causes wastage of space and ambiguities. virtual base classes are used to save space and avoid ambiguities in such cases. For example, following program prints 48. 8 extra bytes are for bookkeeping information stored by the compiler (See this for details)
Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above
Please Login to comment...