What are virtual functions?

Berni44 someone at somemail.com
Wed Apr 14 13:43:20 UTC 2021


I'm trying to understand, what virtual functions are. I found the 
[specs](https://dlang.org/spec/function.html#virtual-functions), 
but I can't make head or tail of it.

- What is a `vtbl[]`? Obviously a function pointer table. But 
where to find this? The examples don't use it. Maybe something 
inside of the compiler?
- Which of the eight functions in the example are virtual and and 
which not? OK B.abc is said to be virtual, as the comment states. 
But it seems never to be used. And why is it considered to be 
virtual?
- There is also the term "covariant function", which is not 
explained. What is this?


I'm asking, because I'm currently writing new docs for 
`std.format`. The [current (stable) docs of 
`formatValue`](https://dlang.org/phobos/std_format.html#formatValue) tell, that some `toString` versions are discouraged, but not for virtual functions. I would like to understand the reason for that, so I can put that properly into the new docs. The reasons, why it's better to not use these versions in normal functions is explained in the [changelog](https://dlang.org/changelog/2.079.0.html#toString). But I miss the reason, why virtual functions should still use them; probably, because I did not understand, what that is.

Can you help me?


More information about the Digitalmars-d-learn mailing list