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
Зарегистрируйся сейчас
или Подпишись на будущие тесты