virtual

Mark a parameter as virtual, and declare a method.

A new function is introduced in the current scope. It has the same name as the declared method; its parameter consists in the declared parameters, stripped from the virtual! qualifier. Calls to this function resolve to the most specific method that matches the arguments.

The rules for determining the most specific function are exactly the same as those that guide the resolution of function calls in presence of overloads - only the resolution happens at run time, taking into account the argument's dynamic type. In contrast, the normal function overload resolution is a compile time mechanism that takes into account the static type of the arguments.

class virtual (
T
)

Examples

Matrix times(double, virtual!Matrix);
string fight(virtual!Character, virtual!Creature, virtual!Device);

Matrix a = new DiagonalMatrix(...);
auto result = times(2, a);

fight(player, room.guardian, bag[item]);

Meta