What will be printed out as a result of the following code execution?
#include <iostream>
class A
{
public:
    A() { f(); }
    virtual void f()
    {
        std::cout << "A::f";
    }
};
class B : public A
{
public:
    void f()
    {
        std::cout << "B::f";
    }
};

int main(int argc, char * argv[])
{
    A * a = new B();
    delete a;
    return 0;
}
Explanation
A non-polymorphic call to polymorphic methods occurs in the constructor.

Следи за CodeGalaxy

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

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