What will be printed out as a result of the following code execution?
#include <iostream>

class A {
        virtual void f() { std::cout << "A"; }

class B : public A {
        void f() { std::cout << "B"; }

void g(A& a) { a.f(); }

int main () {
    B b;
B::f() will be called, even though it is in a private access area. According to the standard, access is checked at the function call point, based on the type of variable through which the function is called. Here, the call point is the place a.f(); and the type of variable is A& a

Слідкуй за CodeGalaxy

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

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