What will be printed out as a result of the following code execution?
#include <iostream>

class A
{
public:
    A() { std::cout << "A "; }
    ~A() { std::cout << "~A "; }
};

class B
{
public:
    B() { std::cout << "B "; }
    ~B() { std::cout << "~B "; }
};

class C: public A
{
    B m_b;
public:
    C() { std::cout << "C "; }
    ~C() { std::cout << "~C "; }
};

int main()
{
    C c;
    return 0;
}
Explanation
Class objects are created from the bottom up, first the base class, then the members, and then the derived class itself. They are being destroyed in the opposite order: first the derived class, members, and then the base class.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести