What will be displayed as a result of the program execution?
#include <iostream>

using namespace std;

struct B
  void f() { cout << "B"; }

struct C: B
  void f() { cout << "C"; }

int main()
  C c;

  B *b1 = &c;

  B b2 = c;
  return 0;
Method B::f() is not a virtual method, so when you access it through the pointer to the object of the base class, this method is called, not the overridden method of the child class.

Слідкуй за CodeGalaxy

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

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