Which figure will be drawn as a result of the following code execution?
struct Base {
   virtual void draw( Color Col = RED ) { 
      // draws square of Col color
   }
};

struct Derived : Base {
   virtual void draw( Color Col = GREEN ) {
      // draws circle of Col color
   }
};

// ... polymorphic method call
Base * B = new Derived;
B -> draw();
Explanation
Never redefine an inherited default parameter value, because default parameter values are statically bound, while virtual functions — the only functions you should be overriding — are dynamically bound.

Следи за CodeGalaxy

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

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