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;
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
Зворотній Зв’язок
Зареєструйся Зараз
або Підпишись на майбутні тести