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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes