Virtual constexpr Function

Get introduced to the virtual 'constexpr' function.

A constexpr function has the potential to run at compile time but can also be executed at run time. Consequently, you can make a constexpr function with C++20 virtual. Both directions are possible. A virtual constexpr function can override a non-constexpr function. Similarly, a virtual non-constexpr function can override a virtual constexpr function. I want to emphasize that override implies that the relevant function of a base class is virtual.

The following program shows both combinations:

Get hands-on with 1400+ tech skills courses.