What will be the output of the following code?
struct A
{
    ~A() { std::cout << "~A()"; }
};

struct B : A
{
    ~B() { std::cout << "~B()"; }
};

struct C : B
{
    ~C() { std::cout << "~C()"; }
};

int main()
{
    std::shared_ptr<A> p(false ? new B() : new C());
    return 0;
}
Explanation
Firstly, the type of ternary expression is converted to the base, in this case, B. Secondly, shared_ptr saves "deleter" for the correct deletion of an object and for this reason a virtual destructor is not required for it.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes