Which method will be called?
class A
{
public:
     virtual int function () {
        return 1;
     }
 
     int get() {
         return this->function();
     }
};
 
class B: public A
{
public:
     int function() {
        return 2;
     }
};
 
#include <iostream>
 
int main() {
   B b; 
 
   std::cout << b.get() << std::endl; 
 
   return 0;
}
Explanation
Despite the fact that there is no get() method in class B, it can be taken from class A, and the result of this method will return calculations for B::function()

Следи за CodeGalaxy

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

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