In C ++, there is one context where the result of overload resolution depends on the type of return on the left side of the expression. This is the initialization / assignment of a function pointer value with a function address. It works with an explicit object of left size, as well as with a temporary object created by an explicit type.
In your case, it can be used to select one specific function from two overloaded ones. For instance:
int (*pfunc)() = func; // selects `int func()` int i = pfunc(); // calls `int func()`
You can use this technique to force overload resolution on a single line, although it does not look too elegant.
int i = ((int (*)()) func)(); // selects and calls `int func()`
Again, in this case, you perform manual overload resolution. C ++ does not have a function that will lead to implicit resolution of overload based on the return type (besides what I illustrated above).
source share