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.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты