fbpx

C++ Interview Question 8 Answer

Bjarne-stroustrup
 

Answer

This question is compilable and deterministic.

Its output is “A”.

Explanation

g(A a) takes an object of type A by value, not by reference or pointer. This means that A's copy constructor is called on the object passed to g() (no matter if the object we passed was of type B), and we get a brand new object of type A inside g(). This is commonly referred to as slicing.

SOURCE