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
Зареєструйся Зараз
або Підпишись на майбутні тести