Virtual function is an actively used design pattern. A virtual function defines a target function to be executed, but the target might not be known at compile time.

?Years Old

Languages with Virtual function include cpp

Example from cpp:

class Animal {
 public:
  // Intentionally not virtual:
  void Move(void) {
    std::cout << "This animal moves in some way" << std::endl;
  }
  virtual void Eat(void) = 0;
};

// The class "Animal" may possess a definition for Eat if desired.
class Llama : public Animal {
 public:
  // The non virtual function Move is inherited but not overridden.
  void Eat(void) override {
    std::cout << "Llamas eat grass!" << std::endl;
  }
};

Last updated June 22nd, 2020

Edit Virtual function on GitHub