What are virtual functions?
Paul Backus
snarwin at gmail.com
Wed Apr 14 13:47:56 UTC 2021
On Wednesday, 14 April 2021 at 13:43:20 UTC, Berni44 wrote:
> 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.
The recommended `toString` versions are templates, but virtual
functions can't be templates (because you can't have a function
pointer that points to a template). So, the non-template versions
are still considered acceptable for cases when `toString` has to
be virtual--i.e., when you're overriding `Object.toString`.
More information about the Digitalmars-d-learn
mailing list