For given class hierarchy in C++, what will be the output of the following code?

#include  <iostream> 
using namespace  std;
class  A
{
public:
    virtual void  Foo(int  n = 10)
    {
        cout << "A::Foo, n = " << n << endl;
    }
};
class  B : public  A{
public:
    virtual void  Foo(int  n = 20) {
        cout << "B::Foo, n = " << n << endl;
    }
};

int  main()
{
    A * pa = new B();
    pa->Foo();
    return  0;
}
Explanation
According to the C++ standard, input function parameters are defined by the static pointer (or reference) type of the object on which the function call is performed.
ISO/IEC 14882: Programming Language C++, §8.3.6, p10

Слідкуй за CodeGalaxy

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

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