[oop] What is the difference between an abstract function and a virtual function?

Binding is the process of mapping a name to a unit of code.

Late binding means that we use the name, but defer the mapping. In other words, we create/mention the name first, and let some subsequent process handle the mapping of code to that name.

Now consider:

  • Compared to humans, machines are really good at searching and sorting
  • Compared to machines, humans are really good at invention and innovation

So, the short answer is: virtual is a late binding instruction for the machine (runtime) whereas abstract is the late binding instruction for the human (programmer)

In other words, virtual means:

“Dear runtime, bind the appropriate code to this name by doing what you do best: searching

Whereas abstract means:

“Dear programmer, please bind the appropriate code to this name by doing what you do best: inventing

For the sake of completeness, overloading means:

“Dear compiler, bind the appropriate code to this name by doing what you do best: sorting”.

Examples related to oop

How to implement a simple scenario the OO way When to use 'raise NotImplementedError'? PHP: cannot declare class because the name is already in use Python class input argument Call an overridden method from super class in typescript Typescript: How to extend two classes? What's the difference between abstraction and encapsulation? An object reference is required to access a non-static member Java Multiple Inheritance Why not inherit from List<T>?

Examples related to language-agnostic

IOException: The process cannot access the file 'file path' because it is being used by another process Peak signal detection in realtime timeseries data Match linebreaks - \n or \r\n? Simple way to understand Encapsulation and Abstraction How can I pair socks from a pile efficiently? How do I determine whether my calculation of pi is accurate? What is ADT? (Abstract Data Type) How to explain callbacks in plain english? How are they different from calling one function from another function? Ukkonen's suffix tree algorithm in plain English Private vs Protected - Visibility Good-Practice Concern

Examples related to abstract

Can we instantiate an abstract class? Is it possible to make abstract classes in Python? Java abstract interface Abstract methods in Java Defining an abstract class without any abstract methods Can we instantiate an abstract class directly? Abstract methods in Python Abstract variables in Java? How do I create an abstract base class in JavaScript? What is the difference between an abstract function and a virtual function?

Examples related to virtual-functions

Can you write virtual functions / methods in Java? Why do we need virtual functions in C++? Can a class member function template be virtual? Calling virtual functions inside constructors Why do we not have a virtual constructor in C++? Can I call a base class's virtual function if I'm overriding it? Safely override C++ virtual functions What is the difference between an abstract function and a virtual function? Virtual member call in a constructor