What will be printed as a result of executing the following program?
#include <iostream>

class Base
{
public:
	virtual void Foo() { std::cout << "Base::Foo "; }
	virtual ~Base(){}
};

class Derived: public Base
{
public:
	void Foo(int k = 0) { std::cout << "Derived::Foo "; }
};

int main()
{
	Base *d = new Derived;
	d->Foo();
	delete d;
	return 0;
}
Explanation
Since there is no function Derived in the class Derived without arguments that would replace the virtual function of the class Base, the function Base::Foo() will be called.

Следи за CodeGalaxy

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

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