3 ms·
The function pointer is initialized at build time, and put into a read-only section in the executable. This is impossible for default arguments, in general. Man
by planede 2y ago
The function pointer is initialized at build time, and put into a read-only section in the executable. This is impossible for default arguments, in general. Many of them would need to be dynamically initialized.
Anyway, it's more than one way antithetical how default arguments work in C++. It's not Python, C++ doesn't have default argument objects in any shape and form. Default argument expressions are expected to be evaluated at call time, with all of its observable implications. The feature itself doesn't mesh well with virtual functions, but there is no reasonable way to resolve it. You either break the intuitions for virtual functions or to default arguments.