[...] there is a deeper reason in the standard why [...]
These questions are usually impossible to answer. Maybe no one thought of it as a useful thing to look into. C ++ generally has limited support for covariance and contravariance. There are many other safe conversions that are potentially possible, not just link qualifications.
For example, a function pointer, such as Animal*(*)(Dog*) , can be initialized from both Animal*(*)(Animal*) and Dog*(*)(Dog*) . But today, support is not supported.
So the real answer is probably: write a sentence .
However, in this case, we can still achieve the desired behavior through a clearly underestimated rule: almost always lambda. We know, by name, the function we want to use and lambdas without capture (which we don't need) can be converted to function pointers:
int (*f)(int&) = [](int& i) { return g(i); };
Barry
source share